Web and email hosting - 270 CHAPTER 9 THE AJAX APPROACH TO

270 CHAPTER 9 THE AJAX APPROACH TO BROWSER SCRIPTING xmlhttp.onreadystatechange = onLoad_LoadXMLHttp; function onLoad_LoadXMLHtpp() { if (xmlhttp.readyState == 4) { ….//do some processing } } Once the readyState value reaches 4, the code needs to check that the content loaded correctly by retrieving the status code of the response. If the status code is 200, the content loaded correctly; other values indicate an error: if (http_request.status == 200) { //success loading var textResponse = xmlhttp.responseText; var xmlDocumentResponse = xmlhttp.responseXML; } else { //error loading } You may want to add more sophisticated error handling to report error messages to the user. You can access the status error message using the statusTextproperty. As shown in the previous example, you can capture the response as text using the responseText property, or as an XML document object using responseXML. If you choose the latter, you can then use the DOM to traverse the document tree. The best way to understand how the object works is to work through some simple examples. In this section, I ll work through the following examples: Making a HEAD request Displaying the contents of an XML document in the browser Using XMLHttpRequest with the DOM You need to run all of these examples through a web server such as Internet Information Services (IIS). If you use IIS, you ll need to save the files to a folder within C:InetPubwwwroot. You can then access the examples through http://localhost/foldername. I ll start by using Ajax to make a HEADrequest. Making a HEAD Request You can make a HEAD request to extract all or some of the headers of a document. You might use this to find the last modified date of a document or to find out its content type. You can find this example saved as getHeaders.htm. Figure 9-2 shows the headers for the document dvd.xml.
You need excellent and relaible webhost company to host your web applications? Then pay a visit to Inexpensive Web Hosting services.

Leave a Reply