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

        }

    }

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.