HTML and CSS Reference
In-Depth Information
Specifies the number of milliseconds to wait before terminating a request. A value of 0
indicates no timeout.
Tracks the progress of the data upload.
In a typical usage, you set responseType and timeout before initiating a request. You then track the
readyState of the request and, when it becomes 4 (complete), access the responseText , responseXML ,
status , and statusText properties.
Methods of XMLHttpRequest
The XMLHttpRequest object provides methods that allow you to initiate a request, send data with the
request, and terminate a request before its completion. Table 11-2 lists these methods for your quick
Table 11-2. Methods of the X MLHttpRequest Object
Method Description
open() Sets the HTTP method and request URL before the request is made. By
default, a request is made in asynchronous fashion, but you can make a
request synchronously using a parameter.
send() Actually sends a request to the server. For all request types other than GET , you
can also pass data as a parameter. The type of data depends on the content
type of the request.
abort() Cancels a request before its completion.
getResponseHeader() Returns the value of a specified HTTP response header once a request is
getAllResponseHeaders() Returns all the HTTP response headers once a request is complete.
Sets a request header (such as Content-Type ). This method must be called
between open() and send() .
In a typical usage, you call the open() method followed by setRequestHeader() , and then call send() to
actually make the request. In most cases, you use the GET or POST verb with the open() method. However,
open() can be used for other verbs too. For example, while using the ASP.NET Web API, you need to pass
PUT and DELETE in addition to GET and POST .
send() can be used to send data depending on the content type. Common data formats are text and
JSON. You can also use FormData object to bundle data as key-value pairs and send it to the server.
Events of XMLHttpRequest
Events of the XMLHttpRequest object allow you to track the request being made and determine its status.
Table 11-3 lists these events.
Search WWH ::

Custom Search