Prev | Current Page 34 | Next

Larry Ullman

"Building a Web Site with Ajax: Visual QuickProject Guide"


function getXMLHttpRequestObject() {
var ajax = false;
}
browsing using Ajax 27
check for Ajax support
Within the function, check what kind of XMLHttpRequest object the browser
supports. If a browser supports a specifi c type of XMLHttpRequest object, make
the ajax variable an object of that type. (See extra bits on page 39.)
2 Older versions of Internet Explorer (that have
ActiveX enabled) should get an XMLHttpRequest
object from one of these two lines.
function getXMLHttpRequestObject() {
var ajax = false;
if (window.XMLHttpRequest) {
ajax = new XMLHttpRequest();
} else if (window.ActiveXObject) {
try {
ajax = new ActiveXObject(???Msxml2.XMLHTTP???);
} catch (e) {
try {
ajax = new ActiveXObject(???Microsoft.XMLHTTP???);
} catch (e) { }
}
}
return ajax;
}
1 Most Web browsers??”Apple??™s Safari 1.2 and later, Mozilla
and Firefox, Opera 8 and later, and newer versions of Internet
Explorer??”should meet this fi rst condition.
3 Finally, this function returns the ajax variable.
4 Save this fi le as ajax.js and place it in the
same directory on your Web server as every
other fi le.


Pages:
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46