jump to navigation

AJAX August 2, 2007

Posted by srideviraghuraman in AJAX.
trackback

AJAX-Asychronous JavaScript and XML

Ajax is a web development technique used for creating interactive web applications.The first use of the term in public was by  Jesse James Garrett in February in 2005.

With Ajax we can create better, faster, and more user-friendly web applications.AJAX is mainly based on JavaScript and HTTP requests.

Ajax uses asynchronous data transfer (HTTP requests) between the browser and the web server, allowing web pages to request small bits of information from the server instead of whole page.

Ajax is a browser technology independent of web server software. Ajax is a cross Platform technology usable on many different operating systems,computer architectures and web browsers.

Ajax is based on Javascripts and HTTP requests. Javascripts is a programming language in   which Ajax function calls are made. Ajax is intented to increase the web page’s interactivity, speed, functionality,usability.

Advantages:

  •             Band width Usage

  •             Separation of data,format,style and function

Disadvantages:

  •            Browser Integration

  •            Response-time concerns

  •            Search Engine Optimization

  •            Reliable on JavaScript

  •            Web Analytics

  •            Accessibility

 Browser Support:

                         Different Browsers use different methods to create XMLHttpRequest Object. Internet Explorer uses ActiveXObject and  while other browsers uses XMLHttprequest.

          Syntax:

          For Firefox, Opera 8.0+, Safari ,

                   XMLHttp=new XMLHttpRequest();

          For Internet Explorer,

                  XMLHttp=new ActiveXObject(“Msxml2.XMLHTTP”);

                                                    (or)

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

HTTP Requests:

   With Ajax, javascript can communicates directly with the server, through the javascript XMLHttpRequest object. With an Http request, a web page can make a request to, and get a response  from a web server without reloading the page.

XMLHttpRequest Object:

It allows interacting with the servers. There are three properties used and they are,

              1.  OnReadyStateChange Property:

                      It is used to receive the data returned by the server. It stores the function  that will process the response from the server.

        Syntax:

         XMLHttp.onreadyStatechange=function()

         {

          //we are going to write some code here

         

              2.  ReadyState Property:

                         It is used to holds the status of the response server’s. Each time the readystate changes, onreadystatechange function will be executed.

                   The possible values for the property are,

                               State                              Description

                                 0                                Request is not initiated 

                                 1                                Request has been set up

                                 2                                Request has been sent

                                 3                                Request is in process

                                 4                                Request is complete

            Syntax:

             XMLHttp.onreadystatechange=function()

             {

                if(XMLHttp.readystate==4)

                {

                 // Get the data from teh server’s response

                 }

            }

            3.  ResponseText Property:

                              The data sent back from the server can be retrieved with the responseText property.

            Syntax:

                XMLHttp.onreadystatechange=function()

                {

                  if(XMLHttp.readystate==4)

                    {

                         document.myForm.time.value=XMLHttp.responseText;

                     }

                 }

Sending Request to the Server:

                  To send off a request to the server, we use the open() method and the send() method. The open() method takes three arguments. The first argument defines which method to use when sending the request (GET or POST). The second argument specifies the URL of the server-side script. The third argument specifies that the request should be handled asynchronously. The send() method sends the request off to the server.

                   Syntax:

                            XMLHttp.open(“GET”,”url”,ture);

                            XMLHttp.send(null);

 

 

Advertisements

Comments»

No comments yet — be the first.

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: