AJAX - The Complete Reference

(avery) #1

Chapter 3: XMLHttpRequest Object 63


PART I


Property or Method Description
open(method, url [,
asynchronous [, user,
password]])

Initializes the request in preparation for sending to the
ser ver. The method parameter is the HTTP method to use,
for example “GET” or “POST”. The value of method is not
case sensitive. The url is the relative or absolute URL the
request will be sent to. The optional asynchronous parameter
indicates whether send() returns immediately or after the
request is complete (default is true, meaning it returns
immediately). The optional user and password arguments are
to be used if the URL requires HTTP authentication. If none
are specified and the URL requires authentication, the user
will be prompted to enter it

setRequestHeader(name,
value)

Adds the HTTP header given by the name (without the colon)
and value parameters
send(body) Initiates the request to the ser ver. The body parameter
should contain the body of the request, i.e., a string
containing fieldname=value&fieldname2=value2... for POSTs
or a null value for GET request

TABLE 3-2 Common Properties and Methods of the XMLHttpRequest Object (continued)

Property or Method Description Browser Support
onload Event triggered when whole
document has finished
loading, similar to looking at
onreadystatechange when
the readyState value is 4.

Firefox 1.5+

onprogress Event triggered as partial
data becomes available. The
event will fire continuously
as data is made available.

Firefox 1.5+

onerror Event triggered when a
network error occurs.

Firefox 1.5+ (still buggy
as of Firefox 2)
overrideMimeType(‘mime-type’) Method takes a string for a
MIME type value (e.g., text/
xml) and overrides whatever
MIME type is indicated in the
response packet.

Firefox 1.5+, Opera
(buggy)

TABLE 3-3 Browser-specific XHR Properties and Methods
Free download pdf