XMLHttpRequest object to behave as AJAX, the async parameter of the openxmlhttp.open( "GET", "AJAX_test.asp", true );Many of the tasks performed on the server are very time consuming. Before AJAX, this operation could cause the application to hang or stop. With AJAX, the JavaScript does not have to wait for the server response, but can instead:
onreadystatechange event:
xmlhttp.open( "GET", "AJAX_info.txt", true ); xmlhttp.send( );
open method to false:
xmlhttp.open( "GET", "AJAX_info.txt", false );Using async=false is not recommended because the JavaScript will NOT continue to execute, until the server response is ready. If the server is busy or slow, the application will hang or stop. Note that when you use async=false, do NOT write an
onreadystatechange function—just put the code after the send statement:
    
<script type="text/javascript">
  function loadXMLDoc( ) {
    var xmlhttp;
    if ( window.XMLHttpRequest ) {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp = new XMLHttpRequest( );
    }
    else {
      // code for IE6, IE5
      xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    }
    xmlhttp.open( "GET", "AJAX_info.txt", false );
    xmlhttp.send( );
    document.getElementById("myDiv").innerHTML = xmlhttp.responseText;
  }
</script>
    
    | 
  
| 
          
     I’m sure wherever my Dad is, he’s looking down on us.      He’s not dead, just very condescending. —Jack Whitehall  |