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); } Link to comment https://forums.phpfreaks.com/topic/176594-returning-httpobjectonreadystatechange/ 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); } } } Link to comment https://forums.phpfreaks.com/topic/176594-returning-httpobjectonreadystatechange/#findComment-931892 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.