Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Never reach readystate 4

    Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?

    function search(method){
    var httpObject = getHTTPObject();
    if (httpObject != null)
    {
    httpObject.open("GET", method, true);
    httpObject.send(null);
    httpObject.onreadystatechange = setOutput(httpObject);
    }
    }

    function getHTTPObject(){
    if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
    else if (window.XMLHttpRequest) return new XMLHttpRequest();
    else
    {
    alert("Your browser does not support AJAX.");
    return null;
    }
    }

    function setOutput(httpObject){
    if(httpObject.readyState == 4)
    {
    alert("Hello world!");
    }
    }
    Last edited by ilbo; 07-19-2009 at 05:15 PM.

  • #2
    Senior Coder ckeyrouz's Avatar
    Join Date
    Jun 2009
    Location
    Montreal, Canada
    Posts
    1,044
    Thanks
    5
    Thanked 179 Times in 179 Posts
    Go to this URL:
    http://www.devguru.com/Technologies/...arseError.html


    you might need to alert(httpObject.parseError.reason)

    there are many xml debugging properties that you can find in this page.

  • #3
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by ilbo View Post
    Hello, for some reason I never reach readystate "4" for when I make a call to the search function below. It doesn't seem to matter if I make the call one or more times, but when I change "true" to "false" in the httpObject.open method, I reach readysate 4. The "method" variable specifies the file name (e.g. "helloworld.php"). Any thoughts?
    Perhaps:

    httpObject.onreadystatechange = function(){ setOutput( this ); };

  • #4
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I'm not outputting any XML though. It's just a PHP script that performs several databasing operations.
    Last edited by ilbo; 07-19-2009 at 11:16 PM.

  • #5
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.

  • #6
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by ilbo View Post
    Also, I'm positive that the setOutput function is being called. I just never get the "4" readystate value.
    Another thing I just noticed is that you must always install the readystatechange handler before calling send.

  • #7
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I moved the readystatechange handler up, but that doesn't seem to do it.

    This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.
    Last edited by ilbo; 07-20-2009 at 12:05 AM.

  • #8
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by ilbo View Post
    I moved the readystatechange handler up, but that doesn't seem to do it.

    This is weird because I get the readystate 4 value when I use "false" in the httpObject.open method.
    Another thing I just noticed is that the request object isn't global so it gets hosed when the creating function ends. That's why it survives for a synchronous request.
    Looks like you made all the common mistakes in one attempt.

  • #9
    New Coder
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    1
    Thanked 0 Times in 0 Posts
    I made it global. No go.

  • #10
    Banned
    Join Date
    Nov 2008
    Location
    not found
    Posts
    284
    Thanks
    0
    Thanked 53 Times in 51 Posts
    Quote Originally Posted by ilbo View Post
    I made it global. No go.
    Perhaps you could show the updated code, or preferably a test URL?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •