Saturday, May 7, 2011

Ajax Programming setup instructions

Ajax Programming :

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  <TITLE> New Document </TITLE>
  <META NAME="Generator" CONTENT="EditPlus">
  <META NAME="Author" CONTENT="">
  <META NAME="Keywords" CONTENT="">
  <META NAME="Description" CONTENT="">
<script type="text/javascript" language="javascript">
  // function to create an XMLHttpClient in a cross-browser manner
  function getAJAXRequest() {
      var xmlhttp=null;;  
      try {
          // Mozilla / Safari / IE7
          xmlhttp = new XMLHttpRequest();
      } catch (e) {
           // IE
           var XMLHTTP_IDS = new Array('MSXML2.XMLHTTP.5.0',
                                     'Microsoft.XMLHTTP' );
          var success = false;
          for (var i=0;i < XMLHTTP_IDS.length && !success; i++) {
              try {
                   xmlhttp = new ActiveXObject(XMLHTTP_IDS[i]);
                   success = true;
                } catch (e) {}
          if (!success) {
              return null;
     return xmlhttp;

 function loadAjaxCall(){
    var http_request=getAJAXRequest();
    //Specifies the type of request, the URL, and if the request should be handled asynchronously or not.
    //method: the type of request: GET or POST
    //url: the location of the file on the server
    //async: true (asynchronous) or false (synchronous)

    var parameters="one="+FristVal+"&sec="+SecVal;

    //Note: When you use async=false, do NOT write an onreadystatechange function - just put the code after the send() statement:
    //Note: When using async=true, specify a function to execute when the response is ready in the onreadystatechange event:'POST', "/projectName/", false);
    http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    http_request.setRequestHeader("Content-length", parameters.length);
    http_request.setRequestHeader("Connection", "close");
    // here the state is synch
    // getting the response as responseText or responseXML

     * Suppose if Asynch we are have to set the readyState
        // here the response is in ready state
                 if (xmlhttp.readyState==4 && xmlhttp.status==200)
// 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

//200: "OK"
//404: Page not found




No comments:

Post a Comment

Java 1.7 New Features Over 1.6

Automatic Resource Management Description: A proposal to support scoping of resource usage in a block with automatic resource cleanup. T...