AJAX has been exciting many programmers as the latest and greatest thing in web development. This article takes a step-by-step look at the Microsoft way to script for AJAX.
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 Properties
The 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