The XMLHttpRequest object is designed to perform one key operation: sending an HTTP
request. The request can be sent either synchronously or asynchronously. The following listing
shows the programming interface of the object as it results from the W3C working draft at
the time of this writing:
interface XMLHttpRequest {
function onreadystatechange;
readonly unsigned short readyState;
void open(string method, string url);
void open(string method, string url, bool async);
void open(string method, string url, bool async, string user);
void open(string method, string url, bool async,
string user, string pswd);
void setRequestHeader(string header, string value);
void send(string data);
void send(Document data);
void abort();
string getAllResponseHeaders();
string getResponseHeader(string header);
string responseText;
Document responseXML;
unsigned short status;
string statusText;
};
Using the component is a two-step operation. First, you open a channel to the URL and specify
the method (GET, POST, or other) to use and whether you want the request to execute
asynchronously. Next, you set any required header and send the request. If the request is a
POST, you pass to the send method the body of the request.
The send method returns immediately in the case of an asynchronous operation. You write an
onreadystatechange function to check the status of the current operation and, using that function,
figure out when it is done.