Chapter 17 Answers
Itâs necessary to write a function for creating new
XMLHTTPRequest
objects 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...catch
construct is to set an error trap for the code inside thetry
statement. If the code causes an error, thecatch
section will be executed instead of a general error being issued.An
XMLHTTPRequest
object has six properties and six methods (see Tables 17-1 and 17-2).You can tell that an Ajax call has completed when the
readyState
property of an object has a value of4
.When an Ajax call successfully completes, the objectâs
status
property will have a value of200
.The
responseText
property of anXMLHTTPRequest
object contains the value returned by a successful Ajax call.The
responseXML
property of anXMLHTTPRequest
object 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
XMLHTTPRequest
objectâsonreadystatechange
property. You can also use an unnamed, inline function.To initiate an Ajax request, an
XMLHTTPRequest
objectâssend
method is called.The main differences between Ajax
GET
andPOST
requests are thatGET
requests append the data to the URL, whilePOST
requests instead pass the data as a parameter of thesend
method ...
Get Learning PHP, MySQL, JavaScript, and CSS, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.