I have the following generic Ajax function:
//run post request
function ajaxPost (divid, parameters, file) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
} else {// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
alert ("ok")
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert ("ready");
alert (xmlhttp.responseText);
divid.innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST", file,true);
//Send the proper header information along with the request
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.setRequestHeader("Content-length", parameters.length);
xmlhttp.setRequestHeader("Connection", "close");
xmlhttp.send(parameters);
}
The problem being that this section does not work as expected:
xmlhttp.onreadystatechange=function() {
alert ("ok")
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert ("ready");
alert (xmlhttp.responseText);
divid.innerHTML=xmlhttp.responseText;
}
}
In browser I get muliple "ok" alerts as I expected but the statements in the if statement never fire. I take this to mean the php is returning state updates but for some reason is never returning ready codes. How that can happen - I have no idea.
Can anyone tell me why I wouldn't recieve the ready codes?
The php itself is not the problem:
<?php
echo "new";
?>
I have tested the function input (divid, parameters and file), and these are ok. This function was previously working in a seperate project.