HTML and CSS Reference
In-Depth Information
EXAMPLE 18.1 ( CONTINUED )
catch (e){
// Internet Explorer Browsers
try{
5
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
return false;
}
}
}
6
return ajaxRequest;
} //End function
EXPLANATION
1
The CreateRequestObject function creates the XMLHttpRequest object for Ajax to
set up communication between JavaScript and the server.
2
This variable will be used to hold a reference to a new Ajax XMLHttpRequest object
created in this function.
3
If the try block has no errors, its statements will be executed; otherwise, the catch
block will be executed.
4
For most modern browsers, this try will succeed. Here the XMLHttpRequest()
method will create a new object called ajaxRequest . (The object name is named
any valid variable name.)
5
The catch blocks are executed if the browser is Microsoft Internet Explorer. Inter-
net Explorer uses the ActiveXObject() method to create the Ajax object rather than
the XMLHttpRequest() method.
6
If successful, an Ajax request object will be returned from this function.
Properties and Methods. The XMLHttpRequest object has several important prop-
erties and methods that will give you information about the status of the request
response, the data that was returned from the server, when the state of the server
changes, and so on. There are methods to initialize the XMLHttpRequest object, send a
request, inform you about what is in the response headers, how to cancel a request, and
so on. You will see the properties and methods in Tables 18.1 and 18.2 used in the Ajax
examples that follow.
 
Search WWH ::




Custom Search