Cross-browser AJAX
-
Comments:
- here.
I need a simple wrapper for a Mozilla/Safari and IE compatible XMLHttpRequest(). Perhaps something like (courtesy of Apple):
1 function loadXMLDoc(url,method,readyFunc) {
2 req = false;
3 if (method) method = "GET";
4 // branch for native XMLHttpRequest object
5 if(window.XMLHttpRequest) {
6 try {
7 req = new XMLHttpRequest();
8 } catch(e) {
9 req = false;
10 }
11 // branch for IE/Windows ActiveX version
12 } else if(window.ActiveXObject) {
13 try {
14 req = new ActiveXObject("Msxml2.XMLHTTP");
15 } catch(e) {
16 try {
17 req = new ActiveXObject("Microsoft.XMLHTTP");
18 } catch(e) {
19 req = false;
20 }
21 }
22 }
23 if(req) {
24 req.onreadystatechange = readyFunc;
25 req.open(method, url, true);
26 req.send("");
27 }
28 return req;
29 }