First of all you could simply try:
if (xmlhttp.readyState == 4) {
alert("readyState: " + xmlhttp.readyState +
"\r\nstatus: " + xmlhttp.status);
}
For a functioning Ajax example, checkhttp://winhlp.com/node/684
.
Hans-Georg
I did change my debug code to agree with your suggestion. Firefox
still fails and IE8 works..
BUT, the results are a little different. The output from the alert is:
readyState: 4
status: 0
And the same failure, "xmlhttp is not defined" now occurs on my next
statement:
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
This statement is not debug code but the actual routine code.
Here is my processajaxcode..
//function to process an XMLHttpRequest
function processajax(serverPage, obj, getOrPost, parmStr) {
//Get an XMLHttpRequest object of use.
xmlhttp = getxmlhttp();
if(getOrPost == "get") {
serverPage += "?" + parmStr;
xmlhttp.open("GET", serverPage);
xmlhttp.onreadystatechange = function() {
// The following 4 lines of code are here for debug purpose.
if(xmlhttp.readyState == 4){
alert("readyState: " + xmlhttp.readyState + "\r\n" +
"status: " + xmlhttp.status);
}
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
response = xmlhttp.responseText;
alert("Response: " + response);
errreturn = response.substr(0,1); // Error if the message is
prefaced by '0'
if(errreturn==0){
alert("Error");
obj = document.getElementById('emsg');
response = response.substring(2);
}
obj.innerHTML = response;
}
}
xmlhttp.send(null);
} else {
xmlhttp.open("POST", serverPage, true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-
urlencoded; charset=UTF-8");
xmlhttp.setRequestHeader("Content-length", parmStr.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
obj.innerHTML = xmlhttp.responseText;
}
}
xmlhttp.send(parmStr);
}
}