I have been trying to change some of our notes forms to use AJAX techniques so there’s no page refreshes.
My code works correctly in Firefox, but IE seems like it refuses to follow my logic.
Here’s the code on a textbox I have in it’s onblur method.
for(count=1;count<=7;count++) {
currDate = ‘Date’ + count;
dateField = document.getElementById(currDate);
dateStr = dateField.value;
dayStr = middle(dateStr,‘/’, ‘/’);
monStr = strLeft(dateStr,‘/’);
yearStr = rightBack(dateStr,‘/’);
getSummary(15, yearStr, monStr, dayStr,‘Testing’, count);
}
here’s the code for getSummary:
function getSummary(numKey, yrKey, monKey, dayKey, objID, c) {
obj = document.getElementById(objID);
roundCount = c;
alert("Count is: "+c);
xmlhttp.open(“GET”, “/Tester.nsf/GetList?OpenAgent&number=” + numKey + “&year=” + yrKey + “&month=” + monKey + “&day=” + dayKey);
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
if (xmlhttp.status == 200) {
var xmlResp = xmlhttp.responseXML;
updateDocument( xmlResp );
} else {
alert ("An error has occured. Error " + xmlhttp.status);
}
} else {
alert("ReadyState: "+xmlhttp.readyState+" Count:"+c);
}
}
xmlhttp.send(null);
xmlhttp.close;
}
Where IE goes out of whack seems to be during the onreadystatechange function.
After showing the alert saying : ReadyState: 1 Count: 1, it goes back to the for loop and increases count by 1, showing another alert saying “Count is 2”, meanwhile the other three alerts say ReadyState: 2 Count: 1, ReadyState: 3 Count: 1. Once the readystate equals 4, the rest of my code goes thinking count is two.
This makes it look like it’s calling getSummary multiple times and almost like it waits while the code inside updateDocument is still running.
Firefox follows the code correctly, only increasing count when all the other code is finished.