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??
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
精彩评论