Jan 27, 2010

Ajax with JavaScript: The XMLHttpRequest Object


As far as class is concerned, I am sure that everyone has understood the concept behind Ajax.
Lets talk about the Remote Scripting, it enables user-side JavaScript to request and receive data from a server without refreshing the web page. By using this technique we can create an application that it uninterrupted making only portions of the page reload with new data. Now this definition sounds like Ajax, right? This is true. Remote scripting is nothing but underlying methodology of Ajax.

Jesse James Garrett wrote an article "Ajax: A New Approach to Web Application"


Limitations of Ajax - It is limited to the kind of browser that runs the web application. The most common forms of Ajax work in the following browsers:
Internet Explorer 5+
Firefox 1+
Opera 9+
Safari 2+

Now lets see how to use Ajax with JavaScript :
We use XMLHttpRequest object to apply Ajax technique. Its is an object created in JavaScript to open HTTP connections and retrieve XML data at the same time.

If we take a look at the iteration 1, all we have to do is retrieve a static file from our web server and add it to our web page.
The interesting things about XMLHttpRequest object is that it has the ability to retrieve other type of data beside XML.
Also, John gave a condition that the code should work in both IE and Firefox.
And we can make it work in both the browsers by creating the object differently in for the browsers.
Once the object is created, the rest of the code is compatible for every browser.

No comments:

Post a Comment