Ajax Won't Get Past Readystate 1, Why?
Solution 1:
I workarounded this problem assigning onload event instead of onreadystatechange:
functionRequest(url, callback){
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
httpRequest = newXMLHttpRequest();
} elseif (window.ActiveXObject) { // IE
httpRequest = newActiveXObject("Microsoft.XMLHTTP");
} else{
returnfalse;
}
var readyStateChange = function(){
console.log(httpRequest.readyState);
if (httpRequest.readyState == 4) {
callback(httpRequest.responseText);
}
};
if (isFirefox && firefoxVersion > 3) {
httpRequest.onload = readyStateChange;
} else {
httpRequest.onreadystatechange = readyStateChange;
}
console.log(httpRequest, url);
httpRequest.open('GET', url, true);
httpRequest.send(null);
}
Solution 2:
Check that the URL in question does actually respond by visiting it directly in the browser.
Test with a different browser do you get the same result.
Use some form of HTTP monitor to watch the client to server conversation (my favorite is Fiddler)
Solution 3:
Possibly the Ajax request doesn't return data (so, a server side error of some kind). Try enabling the option 'show XMLHttpRequests' in the firebug console, to check for this.
Solution 4:
I also faced the same issue. By reading the url below, I got mine solved.
http://bytes.com/topic/javascript/answers/548442-ajax-readystate-1-wall
basically, when I assign my function as the event listener for httpRequest.onreadystatechange, I cannot pass any variable to it. SO that I have to embed the variable inside the HTTP POST string to the server backend then get it back from the HTTP response.
It works fine for FF 3. No need to use jQuery.
Solution 5:
I had the same problem on FireFox but not on Chrome.
The problem was my response had the mime-type set to "application/octet-stream".
Changing it to "text/html" made it work on FireFox too.
Post a Comment for "Ajax Won't Get Past Readystate 1, Why?"