Monday, November 21, 2011

AJAX Notes


AJAX
1.      AJAX= Asynchronous JavaScript and XML
2.      AJAX applications are Browser and platform independent
3.      XMLHttpRequest object: - is used to exchange data with a server behind the scenes. This means that it is possible to update parts of a web page without reloading the whole page.
4.      Syntax for creating XMLHttpRequest object:
Variable xmlhttp =new XMLHttpRequest ();      //for IE 7+, Firefox and chrome
Variable xmlhttp = new ActiveXObject (“Microsoft.XMLHTTP”);     //for IE 5 and IE 6
5.      To handle both type of browser:
Var xmlhttp;
If (window.XMLHTTPRequest)
{
// code for IE 7+, Firefox, chrome, opera, safari
            Xmlhttp= new XMLHTTPRequest ();
}
Else
{
            // code for IE 5 and IE 6
            Xmlhttp= new ActiveXObject (“Microsoft.XMLHTTP”);
}
6.      to send a request to a server, we use open() and send() methods of XMLHttpRequest object
xmlhttp.open (“GET”,”ajax.info.txt”,true);
xmlhttp.send ();
7.      Syntax is:
Open (method,URL,async)
Send (String)  //String is only used for post
8.      Two XMLHttpRequest object properties are:
a.      responseText
b.      responseXML
9.      the onereadystatechange event is triggered every time the ready state changes.
10.  Three important properties of the XMLHttpRequest object:
Property
Description
onreadystatechange
Stores a function (or the name of a function) to be called automatically each time the readyState property changes
readyState
Holds the status of the XMLHttpRequest. Changes from 0 to 4: 
0: request not initialized 
1: server connection established
2: request received 
3: processing request 
4: request finished and response is ready
status
200: "OK"
404: Page not found

No comments :

Post a Comment