View Single Post
Old 03-09-2007, 01:49 AM   PM User | #4
Basscyst
Smokes a Lot


 
Join Date: Jul 2003
Location: CA, USA
Posts: 1,594
Thanks: 5
Thanked 20 Times in 20 Posts
Basscyst is on a distinguished road
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&param2=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);
}
__________________
Helping to build a bigger box. - Adam Matthews
Basscyst is offline   Reply With Quote