Asynchronous JavaScript and XML, is a web development technique for creating interactive web applications. The intent is to make web pages feel more responsive by exchanging small amounts of data with the server behind the scenes, so that the entire web page does not have to be reloaded each time the user requests a change. This is meant to increase the web page's interactivity, speed, and usability.
The Ajax technique uses a combination of:
* XHTML (or HTML) and CSS, for marking up and styling information.
* The DOM accessed with a client-side scripting language, especially ECMAScript implementations such as JavaScript and JScript, to dynamically display and interact with the information presented.
* The XMLHttpRequest object is used to exchange data asynchronously with the web server. In some Ajax frameworks and in certain situations, an IFrame object is used instead of the XMLHttpRequest object to exchange data with the web server, and in other implementations, dynamically added <script> tags may be used.
* XML is sometimes used as the format for transferring data between the server and client, although any format will work, including preformatted HTML, plain text, JSON and even EBML. These files may be created dynamically by some form of server-side scripting.
Like DHTML, LAMP and SPA, Ajax is not a technology in itself, but a term that refers to the use of a group of technologies.
Properties
************
Property Description
onreadystatechange Event handler that fires when the state of the request object changes.
readyState Returns values that indicate the current state of the object.
responseText String version of the response from the server.
responseXML DOM-compatible document object of the response from the server.
status Status code of the response from the server.
statusText Status message returned as a string.
Methods
***********
Method Description
Abort() Cancels the current HTTP request.
getAllResponseHeaders() Retrieves the values of all the HTTP headers.
getResponseHeader("headerLabel") Retrieves the value of an HTTP header from the response body.
open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) Initializes an MSXML2.XMLHTTP request, specifying 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 name of an HTTP header.
Creating the Request Object
*********************************
To create the request object, you must check whether the browser uses the XMLHttpRequest or the ActiveXObject. The primary difference between the objects is the browsers that use them. Windows IE 5 and above use the ActiveX object; Mozilla, Netscape 7, Opera, and Safari 1.2 and above use the XMLHttpRequest object. Another difference is the way in which you create the objects: Opera, Mozilla, Netscape, and Safari allow you to simply call the objects' constructor, but Windows IE requires the name of the object to be passed to the ActiveX constructor. Following is an example of how to write the code to determine which object to use and how to create it:
if(window.XMLHttpRequest)
{
request = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
request = new ActiveXObject("MSXML2.XMLHTTP");
}
Post new comment