function run1() {The problem is, when you have many events to handle, the variable xmlhttp in run1 may have assigned to different instances by different functions (e.g. run2, run3, etc). If you rely on this code, no one can gaurentee that your code will run correctly.
xmlhttp = new XMLHTTPRequest();
xmlhttp.onreadystatechange = processStateChange;
...
}
function processStateChange() {
if (xmlhttp.readyState == 4) ...
}
The resolve this problem you can try to write the code in this way:
function run1() {If you insist to write the handle in a function, here is another style of writing it:
var xmlhttp = new XMLHTTPRequest();
xmlhttp.onreadystatechange = function() { ... }
}
function run1() {
var xmlhttp = new XMLHTTPRequest();
xmlhttp.onreadystatechange = function() {
processStateChange(xmlhttp);
}
...
}
function processStateChange(xmlhttp) { ... }
No comments:
Post a Comment