Chapter 17 Answers
It’s necessary to write a function for creating new
XMLHTTPRequestobjects because Microsoft browsers use two different methods of creating them, while all other major browsers use a third. By writing a function to test the browser in use, you can ensure that your code will work on all major browsers.The purpose of the
try...catchconstruct is to set an error trap for the code inside thetrystatement. If the code causes an error, thecatchsection will be executed instead of a general error being issued.An
XMLHTTPRequestobject has six properties and six methods (see Tables 17-1 and 17-2).You can tell that an Ajax call has completed when the
readyStateproperty of an object has a value of4.When an Ajax call successfully completes, the object’s
statusproperty will have a value of200.The
responseTextproperty of anXMLHTTPRequestobject contains the value returned by a successful Ajax call.The
responseXMLproperty of anXMLHTTPRequestobject contains a DOM tree created from the XML returned by a successful Ajax call.To specify a callback function to handle Ajax responses, assign the function name to the
XMLHTTPRequestobject’sonreadystatechangeproperty. You can also use an unnamed, inline function.To initiate an Ajax request, an
XMLHTTPRequestobject’ssendmethod is called.The main differences between Ajax
GETandPOSTrequests are thatGETrequests append the data to the URL, whilePOSTrequests instead pass the data as a parameter of thesendmethod and ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access