From CodeMonkeyWiki
function getAjaxObject() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
} catch (e) {
// Internet Explorer
try {
xmlHttp=new ActiveXObject('Msxml2.XMLHTTP');
} catch (e) {
try {
xmlHttp=new ActiveXObject('Microsoft.XMLHTTP');
} catch (e) {
alert('This browser is not AJAX comaptible');
return false;
}
}
}
return xmlHttp;
}
function ajaxFunction() {
var url = 'service_to_hit';
var xmlHttp = getAjaxObject();
if (xmlHttp) {
xmlHttp.onreadystatechange=function() {
if (xmlHttp.readyState==4) {
if (xmlHttp.responseXML) {
var doc=xmlHttp.responseXML.documentElement;
// got doc, can do something with the xml
}
} // end xml recieved
} // end readyState = 4
} // end readyState function
sendData(xmlHttp, url);
}
}
function sendData(xmlHttp, url) {
try {
xmlHttp.open('GET',url,true);
xmlHttp.send(null);
} catch (e) {
// could not hit url, or other error happened
}
}