HOME  |  AJAX  |  SOLUTIONS  |  TECHNOLOGIES  |  E-COMMERCE  |  ABOUT US
AJAX Basics
AJAX programming is centered around the XMLHTTPRequest() Object.  This is the piece that makes all AJAX programming possible.  Unfortunatlly, creating the XMLHTTPRequest() object is different for each browser.  Luckly it is fairly simple to write code to use the correct object for the clients browser, and once you create the object, it functions in pretty much the same manner.

Internet Explorer uses an ActiveX object to create its XMLHttpRequst object:
var myRequest = new ActiveXObject("Microsoft.XMLHTTP");

While Mozilla/FireFox and Safari use a native object:

var myRequest = new XMLHttpRequest();
I perfer to create a function that handles all the necessary brower checking that I can use over and over:
//Gets the browser specific XmlHttpRequest Object
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
//Display your error message here.
//and inform the user they might want to upgrade
//their browser.
}
}
You basically have to different options for how you want your results returned. You can either retrieve your data as plain text, or you can retrieve it as XML.  XML is great if your returning multiple values from your XmlHttpRequest.  The only problem with getting your results as XML is that you need to know how to walk the XMLDOM in JavaScript.  If your just returning a single value, then it is probably easier to just stick with plain text.