Hi
Ive been using some httpRequests but have gotten tired of writing the 'preparation code' for every request... so I thought I'd make a function that accepted a URL, and a list of parameters and would return the responseText variable...
But what seems to happen is that my other code continues without the ajaz call being completed... and so if I perform an operation on that responseText variable, it shows as 'undefined'...
I thought if I adjusted my ajaz function to accept a function name as well which would operate on the responseText, it would solve the problem... I think Ive seen someone pass a function as an argument before... is that possible? Or is there a uniform solution for avoiding writing ajax code...? my ajaxCall function is below:
function ajaxCall(path,querystring){
//new http request object
var http;
http=GetXmlHttpObject();//use another function to create the correct object
var url = path;
var params = querystring;
http.open("POST", url, true);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
return http.responseText;
}
}
http.send(params);
}
var returnContent = ajaxCall('www.mysite.com/userdetails.php','name=John&surname=Smith');