Ajax Readystate Always Equals One
Hello I'm working with ajax that submits to a C++ cgi program. The problem that I am having is the readyState is always 1. I don't get what I am doing wrong. var asyncRequest;
Solution 1:
Move the SateChange function to the body of the function where the XHR is being made. After this modification, the asyncRequest
inside StateChange
will equal the relevant asyncRequest
object.
function ajaxUpdate(){
....
var asyncRequest; // XMLHttpRequest object
try {
asyncRequest = new XMLHttpRequest();
....
asyncRequest.send(postData);
}
catch (exception){
alert("Request failed: " + exception.message);
}
//} <---Removed curly bracket
function StateChange(){
// Make sure request has completed with 200 OK status
//alert(asyncRequest.status)
if (asyncRequest.readyState == 4 && asyncRequest.status == 200){
alert("Hello");
}
}
} //<--Added curly bracket!
Post a Comment for "Ajax Readystate Always Equals One"