Method | Description |
---|---|
abort() | Cancels the current request |
getAllResponseHeaders() | Returns all HTTP headers as a String type variable |
getResponseHeader() | Returns the value of the HTTP header specified in the method |
open() | Specifies the different attributes necessary to make a connection to the server; allows you to make selections such as GET or POST (more on that later), whether to connect asynchronously, and which URL to connect to |
setRequestHeader() | Adds a label/value pair to the header when sent |
send() | Sends the current request |
abort()
The abort method is really quite simple—it stops the request in its tracks. This function can be handy if you are concerned about the length of the connection. If you only want a request to fire for a certain length of time, you can call the abort method to stop the request prematurely.
getAllResponseHeaders()
You can use this method to obtain the full information on all HTTP headers that are being passed. An example set of headers might look like this:
Date: Sun, 13 Nov 2005 22:53:06 GMT Server: Apache/2.0.53 (Win32) PHP/5.0.3 X-Powered-By: PHP/5.0.3 Content-Length: 527 Keep-Alive: timeout=15, max=98 Connection: Keep-Alive Content-Type: text/html
getResponseHeader("headername")
You can use this method to obtain the content of a particular piece of the header. This method can be useful to retrieve one part of the generally large string obtained from a set of headers. For example, to retrieve the size of the document requested, you could simply call getResponseHeader ("Content-Length").
open ("method","URL","async","username","pswd")
Now, here is where we start to get into the meat and potatoes of the XMLHttpRequest object. This is the method you use to open a connection to a particular file on the server. It is where you pass in the method to open a file (GET or POST), as well as define how the file is to be opened. Keep in mind that not all of the arguments in this function are required and can be customized depending on the situation.
setRequestHeader("label","value")
With this method, you can give a header a label of sorts by passing in a string representing both the label and the value of said label. An important note is that this method may only be invoked after the open() method has been used, and must be used before the send function is called.
send("content")
This is the method that actually sends the request to the server. If the request was sent asynchronously, the response will come back immediately; if not, it will come back after the response is received. You can optionally specify an input string as an argument, which is helpful for processing forms, as it allows you to pass the values of form elements.