Suchy Posted October 5, 2009 Share Posted October 5, 2009 I want to return data from httpObject.onreadystatechange = function () . How can I retrieve the data from this function inside my validate() function, which this one is inside ? validate() { ... httpObject.send(null); httpObject.onreadystatechange = function () { if(httpObject.readyState == 4) { var res = httpObject.responseText; if (res == "0") return 0; else return 1; } } ... alert (httpObject.onreadystatechange); } Quote Link to comment Share on other sites More sharing options...
corbin Posted October 6, 2009 Share Posted October 6, 2009 Since onreadstatechange is a method called when ever the readystate changes (meaning you can't control when it's called), there isn't a feasible way to return a value from it. You can, however, call a function from inside of the method that contains the readyState: blah.onreadystatechange = function() { if(this.readyState == 4) { if(this.responseText == "0") { someFunction(0); } else { someFunction(1); } } } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.