AJAXxXxX…

AJAX stands for Asynchronous JavaScript And XML. AJAX is a new type of programming that provides for a way to use existing standards. With AJAX a programmer can create better, faster and more user-friendly web applications. It is based on JavaScript and HTTP requests. With AJAX, web applications can retrieve data from the server ‘asynchronously’ in the background without interfering with the display and behaviour of the existing page. Asynchronously means that a webpage users HTTP requests between the browser (eg. Firefox) and the web server. It also means that data is not sent in a sequence. Ajax makes it possible to update a page without a refresh. Using Ajax, we can refresh a particular DOM object without refreshing the full page.. An advantage of this is quicker response, increase interactivity, allowing pages to be reloaded individually. The development of this language has led to an increase in the use of animation of web pages.

XMLHttpRequest allows a JavaScript program to send an HTTP request to a server and receive back a response containing an XML document. Firefox and IE treat this differently:

CODE for XMLHttpRequest


  • For IE, use the following Javascript:

var req = new ActiveXObject(“Microsoft.XMLHTTP”);

  • …for other browsers, use:

var req = new XMLHttpRequest();

http://www.omnytex.com/articles/xhrstruts/

Differences in IE and Firefox treatment of XMLHTTPRequest

http://powerdream5.wordpress.com/2007/10/11/ajax-ie-and-firefox/

readyState and XMLHTTPRequest?

readyState: Return the current status of the request, read-only property.

The readyState property can take a value from 0 to 4 (0=UNINITIALIZED, 1=LOADING, 2=LOADED, 3=INTERACTIVE, 4=COMPLETED). A value of 4 (i.e., COMPLETED) means that receiving the response from the server is completed and the response data is available through properties of the XMLHTTP object. For the readyState property to reach the value of 4, this property changes the value four times (i.e., from LOADING to COMPLETED), so the HandleResponse function gets called four times for each response. To make sure that the data is available in the XMLHTTP object, the XmlHttp.readyState property is compared to the value of 4 in the HandleResponse function.
If the readyState of the XMLHTTP instance has a value of 4, we then need to check its status property to make sure that a valid response was received.

Major benefit of using XMLHTTPRequest?

The major benefit of the XMLHTTPRequest is that there is no need for a page to refresh to show an addition of data.

Resources:

http://www.w3schools.com/Ajax/Default.Asp

http://en.wikipedia.org/wiki/Ajax_(programming)

http://www.w3schools.com/Ajax/ajax_httprequest.asp

Leave a comment

Filed under Uncategorized

Leave a comment