Hi all,
I have noticed that some of my ajax calls do not reach a readystate of 4, and just sit somewhere between state 1 & 3. I use the w3schools recommended method i.e. [
w3schools.com...]
My code is below, and I am not sure why it works fine sometimes, and not others. This happens across IE, Chrome and Firefox intermittently:
var xmlHttp;
function my_ajax_function(content){
var xmlHttp=GetXmlHttpObject();
var url="page.php";
var params = "value="+content;
xmlHttp.open("POST", url, true);
xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlHttp.setRequestHeader("Content-length", params.length);
xmlHttp.setRequestHeader("Connection", "close");
xmlHttp.onreadystatechange = function() {
if(xmlHttp.readyState == 4 && xmlHttp.status == 200) {
//ok
} else if(xmlHttp.readyState == 4 && xmlHttp.status != 200){
//error
}
}
xmlHttp.send(params);
}
function GetXmlHttpObject(){
var xmlHttp=null;
try{
xmlHttp=new XMLHttpRequest();
}catch(e){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}