I use this little function I wrote, I guess it's creating a new one each time. The only thing I don't like about it is the eval for the call back function, but I can't think of another way to reliably pass values from the initiation of the request to the call back function.
Code:
var x=4;
getReqObjPost("someurl.asp","param1=1¶m2=2","callBack(xml,"+x+")");
Code:
//*******************************************************
// Sends an asyncronous xmlhttp request using post
// Pass the URL, Querystring, and callback function (as a string)
//*******************************************************
function getReqObjPost(url,params,func)
{
if (window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
else if (window.ActiveXObject){
if(new ActiveXObject("Microsoft.XMLHTTP")){
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
else{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var str=xmlhttp.responseText;
var xml=xmlhttp.responseXML;
eval(func);
}
else{
noData(xmlhttp.status,url);
}
}
}
var now=new Date();
params=params + "&c_date"+now.getSeconds()+"=" + now;
xmlhttp.open("POST",url,true);
xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
xmlhttp.send(params);
}