| Definitions | |
|---|---|
| Abort() | Cancels the current HTTP request. |
| getAllResponseHeaders() | Retrieves the values of all the HTTP headers. |
| geTResponseHeader("label") | Retrieves the value of a specified HTTP header from the response body. |
| Open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) | Initializes an MSXML2.XMLHTTP or Microsoft.XMLHTTP request, and specifies the method, URL, and authentication information for the request. |
| Send(content) | Sends an HTTP request to the server and receives a response. |
| SetRequestHeader("label", "value") | Specifies the value of an HTTP header based on the label. |
My Blog List
-
Hello world! - Welcome to WordPress. This is your first post. Edit or delete it, then start writing!9 years ago
Wednesday, June 25, 2008
A List of XHR Methods and Corresponding Definitions
Friday, June 13, 2008
Creating the Object
With a better understanding of the XHR and different request models, we can now focus on creating the object. Creating the request object is trivial in comparison to the power that is unleashed when applying it to a project.
To create the request object, you must check to see if the browser uses the XHR or the ActiveX object. The primary difference between the objects is the browsers that use them. Windows Internet Explorer (IE) 5 and above use the ActiveX object, whereas Mozilla, Firefox, Netscape, Opera, and Safari use the native JavaScript XHR object. The second difference is the way in which we create each object: Windows IE requires the name of the object to be passed as a parameter to the ActiveX constructor, whereas the other browsers provide us with the native JavaScript object, which only we need to instantiate:
function makeRequest(url)sendRequest(url);
{
if(window.XMLHttpRequest)
{
request = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request = new ActiveXObject("Msxml2.XMLHTTP");
}
}
As you can see from the code sample, the object creation is really a very simple task. We create a method named makeRequest to handleyou guessed itmaking the request and to decipher what type of object the browser uses by creating a condition that checks for the native XHR object. If this object is not available, we check for the ActiveXObject. After the correct object type has been identified for the current browser, the correct object is instantiated and a request object is created. This object can now be used to access all the properties and methods listed in which are available to the XHR object.