Thursday, December 30, 2010

What is AJAX

AJAX stands for "Asynchronous JavaScript And XML".
It is a browser technology independent of web server software. It can directly communicate with the server using the Javascript XMLHttpRequest object. We can say that by the use of this object, JavaScript has become able to trade data directly with the server. With an HTTPRequest, a web page can make a request to, and get a response from a web server without reloading the page. The user will stay on same page and he/she will not notice that scripts request pages or send data to a server in the background. The best example which we she everyday is google suggest. Now, we can assume how much an AJAX application is useful! But, it is not useful everywhere. It has also some drawbacks too. So, it is not preferable to apply AJAX everywhere.
There are two ways that AJAX can access the server.
Synchronous :- In this way, script stops and waits for the server to send back a reply before continuing.
Asynchronous :- In this way, script allows the page to continue to be processed and will handle the reply if and when it arrived. Due to implementation of this way, processing become richer,user friendly, smoother as well as reduce the gap between desktop application and web application.
AJAX is based on following web standards:
  • JavaScript
  • XML
  • HTML
  • CSS
Different browsers uses different methods to use XMLHttpRequest object. For example, Firefox,Opera,Safari,Netscape use JavaScript built-in method - XMLHttpRequest while IE uses ActivexObject.

Properties of  XMLHttpRequest object
  1. onreadystatechange
  2. readystate
  3. responseText
  4. responseXML
  5. status
  6. statusText  
Methods of  XMLHttpRequest object
  1. open()
  2. send()
  3. abort()
  4. getAllResponseHeaders()
  5. getResponseHeaders()
  6. setRequestHeader()
Best way to use AJAX using jQuery is below:
google.load("jqueryui", "1.8.2");
var total;
total = jQuery.ajax({url: live_site+"/plugins/content/extravote/ajax.php",global: false, type: "POST",data: ({task : "getrating",cid:id,xid:xid,column_name:"rating_sum",dummy:new Date().getTime()}),
      dataType: "text",async:false,
      success: function(msg){ }
   }
).responseText;
alert(total);

    No comments:

    Post a Comment

    Thanks for your valuable comments.

    Important queries based formulas to watch performance of a MySQL based application

    (1) Session Vs global status variables value select G.variable_name,G.variable_value GlobalValue,S.variable_value SessionValue from (selec...