javascript - Ajax Request returns undefined result -
i have problem ajax request ( basic function )
here's ajax function
function ajax(){ var activexmodes=["msxml2.xmlhttp", "microsoft.xmlhttp"] if (window.activexobject){ (var i=0; i<activexmodes.length; i++){ try{ return new activexobject(activexmodes[i]) } catch(e){ } } } else if (window.xmlhttprequest) return new xmlhttprequest() else return false } here function
_2xm.load = function (p, type) { p = p.replace("frame_", ""); loading(type); var req=new ajax(); var __page =encodeuricomponent(p); req.open("get", "page.php?page="+__page, true); req.send(null); req.onreadystatechange=function(){ if (req.readystate==4) { if (req.status==200 || window.location.href.indexof("http")==-1) { loading(2); return req.responsetext; } else { loading(2); return "an error occured.... "; } } } } here part of code uses _2xm.load() function :
_2xm.loaddata = [_2xm.load(pg, 0), _2xm.now(), _2xm.interval * 60]; but result allways undefined, why?
you never returned value _2xm.load, function implicitly evaluates undefined.
you return values anonymous function callback bound req.onreadystatechange, fires @ later stage, asynchronously, long after function call _2xm.load has finished.
perhaps should consider synchronous request.
Comments
Post a Comment