Cross-browser AJAX
-
Comments:
- here.
I need a simple wrapper for a Mozilla/Safari and IE compatible XMLHttpRequest()
. Perhaps something like (courtesy of Apple):
function loadXMLDoc(url,method,readyFunc) {
req = false;
if (method) method = "GET";
// branch for native XMLHttpRequest object
if(window.XMLHttpRequest) {
try {
req = new XMLHttpRequest();
} catch(e) {
req = false;
}
// branch for IE/Windows ActiveX version
} else if(window.ActiveXObject) {
try {
req = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try {
req = new ActiveXObject("Microsoft.XMLHTTP");
} catch(e) {
req = false;
}
}
}
if(req) {
req.onreadystatechange = readyFunc;
req.open(method, url, true);
req.send("");
}
return req;
}