1
function loadxmldoc()
{
  var xmlhttp;
  if (window.XMLHttpRequest)
  {
     xmlhttp=new XMLHttpRequest();
  }
  else
  {
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

 xmlhttp.onreadystatechange=function()
 {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
      document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
    } 
 }

 xmlhttp.open("GET","ajax_info.php?fname=sakthi&lname=karthiga",false);

 xmlhttp.send();
}

ajax_info.php

<?php
  echo( "hello"."<br>".$_GET["fname"].$_GET["lname"]); 
?>

in this code i change the ajax status as FALSE but stil working same as TRUE can u tell whats the difference b/w TRUE and false? if i change false what will going on serverside

1

1 Answer 1

2

I suppose that you are talking about the third parameter of the open function. It indicates whether the request should be asynchronous or not. In both cases the exactly same request will be sent to the server. The difference will be on the client. If you use asynchronous (which is the recommended for AJAX) the client browser will not freeze during the execution of the request and the send method will return immediately. Once the execution on the server finishes, the callback you subscribed to will be invoked.

If you set the parameter to false the send method will block and freeze the client browser during the entire execution of the request to the server. This completely defeats the whole purpose of AJAX but it is used by some people that want to use the results of the request outside of the success callback. Do not do the same mistake.

I would very strongly recommend you to always use asynchronous AJAX requests (true) and not blocking calls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.