1

I am curious as to why my AJAX-call is failing in Google Chrome, it works perfectly fine in Firefox. Before anyone asks, no I'm not using JQuery because I need to have access to readyState == 3 which JQuery doesn't seem to have.

My script currently looks like this(with large unneccessary parts stripped out):

function fetch()
{
    main = new XMLHttpRequest();
    main.open("GET", "<?php echo anchor("thescript"); ?>", true);

    var lastResponse = '';
    var statusString = 'Step 1(of 3), please wait... ';

    main.onreadystatechange = function()
    {
        if( main.readyState == 1 ) 
        {
            alert('Fetch!');
            $("#ajax-status").html( statusString );
        }

        // If there's been an update
        if( main.readyState == 3 )
        {
        }
        if( main.readyState == 4 )
        {
        }
    };
    main.send(null);
}

It works perfectly in Firefox but in Chrome it doesn't even alert anything so it doesn't even get into readyState 1(which is when you send it) -- that seems rather odd..

Any ideas??

Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265
Tanax
  • 433
  • 2
  • 10
  • 20
  • http://stackoverflow.com/questions/287286/jquery-is-req-readystate-3-possible – John Kurlak Sep 26 '11 at 20:26
  • does it any difference to put the .open() after you set .onreadystatechange ? – Einacio Sep 26 '11 at 20:28
  • This might also be of use, http://stackoverflow.com/questions/3880381/xmlhttprequest-responsetext-while-loading-readystate-3-in-chrome/4752861#4752861 – Andrew Sep 26 '11 at 20:32
  • First link does not work anymore. JQuery xhr doesn't include onreadystate property(which is says in the link if you read the comments) – Tanax Sep 26 '11 at 20:43
  • Regarding the second link, about the Chrome bug, how does one set the "content type" as you specify in your post on that topic?? – Tanax Sep 26 '11 at 20:44
  • And yes Ein~, it actually does a difference! The readystate's are now working properly, I think! I recieve the alert when it sends the request and I also tried an alert in readyState == 3 and it alerts that too. However, the response seems to be empty for some reason :/ – Tanax Sep 26 '11 at 20:48

1 Answers1

0

As noted above:

does it any difference to put the .open() after you set .onreadystatechange

And yes Ein~, it actually does a difference! The readystate's are now working properly, I think! I recieve the alert when it sends the request and I also tried an alert in readyState == 3 and it alerts that too. However, the response seems to be empty for some reason

Community
  • 1
  • 1
Paul Sweatte
  • 24,148
  • 7
  • 127
  • 265