javascript - o From XMLHTTPRequest is Undefined -


so, lifted nice ajax code site. problem such lame javascript programmer can figure out how output onto page. startup() function says o undefined. see results of php on firebug console.

tia help.

var asyncrequest = function() {   function handlereadystate(o, callback) {     if (o && o.readystate == 4 && o.status == 200) {       if (callback) {         callback(o);       }     }   }    var getxhr = function() {     var http;     try {       http = new xmlhttprequest;         getxhr = function() {           return new xmlhttprequest;         };     }     catch(e) {       var msxml = [         'msxml2.xmlhttp.3.0',          'msxml2.xmlhttp',          'microsoft.xmlhttp'       ];        (var i=0, len = msxml.length; < len; ++i) {         try {           http = new activexobject(msxml[i]);           getxhr = function() {             return new activexobject(msxml[i]);           };            break;         }          catch(e) {}       }     }      return http;    };    return function(method, uri, callback, postdata) {     var http = getxhr();     http.open(method, uri, true);     handlereadystate(http, callback);     http.send(postdata || null);      return http;   };  }();  asyncrequest('get', 'voterserver.php', function(o) {     console.log(o.responsetext); });  function startup() {     //alert("here!");     document.getelementbyid("user_list").innerhtml=o.responsetext; } 

the asyncrequest takes callback function 3rd parameter thats

function(o) {     console.log(o.responsetext); } 

within it

the value of o passed function , not available in startup function.

you need rewrite startup follows

function startup() {     asyncrequest(       'get',        'voterserver.php',        function(o)        {           document.getelementbyid("user_list").innerhtml=o.responsetext;       }); } 

i've set indentation make clearer.

you may want @ using 1 of javascript frameworks makes sort of thing alot easier , has documentation, use mootools jquery popular.

update

i tried make jsfiddle thte code put in question , didnt work, i've made changes work , here try.

same thing mootools mootools


Comments

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -