async javascript function issue -
i having problem javascript function callback.
for example have code this:
var base = { // constructor of class createnew: function(name) { var base = {}; base.ajax = function(callback, url) { // create xmlhttprequest object var httprequest; if (window.xmlhttprequest) { httprequest = new xmlhttprequest(); } else if (window.activexobject) { httprequest = new activexobject("microsoft.xmlhttp"); } httprequest.onreadystatechange = function() { // check status of our request // called on every state change if (httprequest.readystate == 4 && httprequest.status == 200) { // call callback function callback.call(httprequest.responsetext); } }; httprequest.open("get", some_url, true); httprequest.send(); }; return base; } };
and create class inherits base:
var test = { createnew: function() { var test = base.createnew(); test.json = {}; test.ajax( function(){ test.json = json.parse( ); }); return test; } };
and create class call mytest inherits test:
// create class 300x250 var mytest = { createnew: function() { var mytest = test.createnew(); return mytest; } }; var mytest = mytest.createnew(); console.log(mytest.json);
however, when try console.log(mytest.json), can't data. know it's because in test class, json in ajax function, don't know how solve async problem, idea?
Comments
Post a Comment