Ajax Tutorial
Ajax Tutorial
AJAX, shorthand for Asynchronous JavaScript and XML, is a web development technique
for creating interactive web applications.
AJAX meant to increase the web page's interactivity, speed, and usability.
If you know Javascript, HTML, CSS and XML then you need to spend just one hour to
startwith AJAX.
AJAX stands for Asynchronous JavaScript and XML. AJAX is a new technique for
creating better, faster, and more interactive web applications with the help of XML,
HTML, CSS and Java Script.
Ajax uses XHTML for content and CSS for presentation, as well as the Document Object
Model and JavaScript for dynamic content display.
Conventional web application trasmit information to and from the sever using
synchronous requests. This means you fill out a form, hit submit, and get directed to a
new page with new information from the server.
With AJAX when submit is pressed, JavaScript will make a request to the server,
interpret the results and update the current screen. In the purest sense, the user would
never know that anything was even transmitted to the server.
XML is commonly used as the format for receiving server data, although any format,
including plain text, can be used.
A user can continue to use the application while the client program requests information
from the server in the background
Intuitive and natural user interaction. No clicking required only Mouse movement is a
sufficient event trigger.
JavaScript
DOM
CSS
Allows for a clear separation of the presentation style from the content and may be
changed programmatically by JavaScript
XMLHttpRequest
AJAX Examples
Google Maps
A user can drag the entire map by using the mouse instead of clicking on a button
or something
http://maps.google.com/
Google Suggest
As you type, Google will offer suggestions. Use the arrow keys to navigate the
results
http://www.google.com/webhp?complete=1&hl=en
Gmail
Gmail is a new kind of webmail, built on the idea that email can be more intuitive,
efficient and useful
http://gmail.com/
The XMLHttpRequest object is the key to AJAX. It has been available ever since Internet
Explorer 5.5 was released in July 2000, but not fully discovered before people started to talk
about AJAX and Web 2.0 in 2005.
XMLHttpRequest (XHR) is an API that can be used by JavaScript, JScript, VBScript and other
web browser scripting languages to transfer and manipulate XML data to and from a web server
using HTTP, establishing an independent connection channel between a web page's Client-Side
and Server-Side.
The data returned from XMLHttpRequest calls will often be provided by back-end databases.
Besides XML, XMLHttpRequest can be used to fetch data in other formats, e.g. JSON or even
plain text.
You already have seen couple of examples on how to create a XMLHttpRequest object.
Below is listed some of the methods and properties you have to become familiar with.
XMLHttpRequest Methods
abort()
Cancels the current request.
getAllResponseHeaders()
Returns the complete set of HTTP headers as a string.
getResponseHeader( headerName )
Returns the value of the specified HTTP header.
send( content )
Sends the request.
XMLHttpRequest Properties
onreadystatechange
An event handler for an event that fires at every state change.
readyState
The readyState property defines the current state of the XMLHttpRequest object.
Here are the possible values for the readyState propery:
State
Description
readyState=0 after you have created the XMLHttpRequest object, but before you have
called the open() method.
readyState=1 after you have called the open() method, but before you have called send().
readyState=2 after you have called send().
readyState=3 after the browser has established a communication with the server, but
before the server has completed the response.
readyState=4 after the request has been completed, and the response data have been
completely received from the server.
responseText
Returns the response as a string.
responseXML
Returns the response as XML. This property returns an XML document object, which can
be examined and parsed using W3C DOM node tree methods and properties.
status
Returns the status as a number (e.g. 404 for "Not Found" and 200 for "OK").
statusText
Returns the status as a string (e.g. "Not Found" or "OK").
AJAX is growing very fast and that is the reason that it contains many issues with it. We hope
with the passes of time they will be resolved ab AJAX will be ideal for web applications. We are
listing down few issues which AJAX has as a challenge.
Complexity is increased
Server side developers will need to understand that presentation logic will be required in
the HTML client pages as well as in the server-side logic