Jump to content

Returning httpObject.onreadystatechange


Suchy

Recommended Posts

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

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);

        }

    }

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.