Step by Step to AJAX - XMLHttpRequest Object Methods
(Page 4 of 5 )
This short list of methods is shared by all supported browsers. In this tutorial we shall look at some of the highlighted methods.
- abort()
- current request is stopped
- getAllResponseHeaders()
- returns a string containing information of headers
- getResponseHeader ("headerlabel")
- returns a string containing information about a single header
- open("method", "URL"[,asyncFlag[,"userName"[,"password"]]])
- assigns various request attributes
- send(content)
- Transmits the data with information that may be posted, if needed
- setRequestHeader ("label", "value")
- assigns label, value pair for the header
While open() and send() are most often used, the others are also useful in some cases. The open() method begins the interaction and takes two mandatory arguments; the "method" used to open, which is either GET or POST, and the URL to which the request is made.
The GET and POST methods are similar to those used in ASP, as some of you might recognize. The GET is indicated for retrieving read only data while POST is for sending data to the server.
The URL could be complete, or a relative URL.
The third parameter which is optional (default value TRUE being asynchronous) sets the interaction to be synchronous (FALSE) or asynchronous (TRUE). If you choose the synchronous route, the script waits for the response to arrive before acting. The useful mode is to set the interaction to be asynchronous and use the onreadystatechange event (to be discussed) to get at the response.
XMLHttpRequest Object PropertiesThe following read only properties are browser agnostic (all supported browsers understand them).
- onreadystatechange
- Event handler which fires every time the state changes
- readState
- Integer representing the status of the object
0 = uninitialized
1 = loading
2 = loaded
3 = interactive
4 = complete
- responseText
- Data returned in string format
- responseXML
- Data returned in DOM Compatible format
- status
- Numeric code returned by server indicating status
404: Not found
200: OK - statusText
- Message string that came with the status
Next: Fetching a page using AJAX >>
More XML Articles
More By Jayaram Krishnaswamy