AJAX Request

Ajax sends a request to the server with following some method, the methods are “open()” and “send()”, the open method uses three augments, first is method type, second is defined the url of the server side script and the third one is specifies that the request should be handled asynchronously and the send method is sends the request off to the server.
 
The format of the open and send method are:
 
xmlhttp.open(“GET”,”validate.php”,true);
xmlhttp.send(null);
 
It Initiates and process an ajax request. It simply allows to interact with the server.
 
Use:
 
new Ajax.Request(url[, options])
 
Actually this object is made for wrapping an instance of XMLHttpRequest and provides the facilities for setting function that are called before a request is made and after a request returns. This is made for handling the server response.
 
Point to be remember that whenever an Ajax request is sent to the server, a special header named “X-Requested-With” with a value of XMLHttpRequest is attached to the request.
 
Example:
 
function ajaxReq() {
   return (isset($_SERVER['HTTP_X_REQUESTED_WITH'])
              &&
            ($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}
 
IT would be very clear on seeing the code that, if the function return true then you received an ajax request otherwise return a normal request on receiving false.
Scroll to Top