AJAX

AJAX HTML and Server Interaction

 

AJAX stands for asynchronous Javascript and XML. The first A in AJAX stands for asynchronous which means that it is able to perform its tasks in the background alongside everything else that is happening, allowing the webpage to continue functioning instead of having to wait for the JavaScript and XML interaction to finish and reload the page (image above).

The XMLHTTPRequest is an object used to communicate asynchronously with a server from a scripting language such as JavaScript. The XMLHTTPRequest not only sends communication to the server but also returns the response from the server straight back into the script it was called from.

Internet explorer (the usual suspect) treats the XMLHTTPRequest differently to the rest of the web browsers due to earlier versions of internet explorer not having the XMLHTTPRequest defined in their scripting languages as it was not a standard at the time. The following snippet of code can be used as a workaround for this:

 

if (window.XMLHttpRequest)

{

// code for IE7+, Firefox, Chrome, Opera, Safari

xmlhttp=new XMLHttpRequest();

}

else

{

// code for IE6, IE5

xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);

}

 

The readyState property contains the current status of the XMLHTTPRequest. When the server receives a request it sends back a series of responses called callbacks which proceed from 0 to 4. When the readyState property equals 4 it means the request is ready to be sent back to the script it was called from.

The major benefit of using the XMLHTTPRequest is that you can send, request and receive data from a server asynchronously and update a webpage without reloading it.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: