How to use AJAX in PHP
By
Neeraj Kumar
February 19, 2010
PHPAND AJAX
Most of the people knows Google earth, Google Maps, Google Mail etc,. But very few people know that lots of Google services are based on Ajax. Now you might be wondering what is AJAX. So let me tell u that it is old technology with some new tricks. Ajax directly communicates with server. It makes requests to the server and collects response from server. Ajax does this all behind the scenes means user does not know that the page is refreshing XMLHttpRequest is the heart of Ajax. It is a JavaScript object. Now if this is an object so obviously it will have properties and methods. This XMLHttpRequest make request to the server and collects response
XMLHttpRequest has a readystate property which tells the status the request on server. It has values as follows:
Description:
-The request is not initialized
-The request has been set up
-The request has been sent
-The request is in process
-The request is complete
The XMLHttpRequest object stores any data retrieved from a server as a result of a server request in its responseText property. There is one open() method takes three arguments. The first argument defines which method to use (GET or POST). The second argument specifies the name of the server resource (URL). The third argument specifies if the request should be handled asynchronously.
The onreadystatechange property stores a function (or the name of a function) to be called automatically each time the readyState property changes. The send () method sends request to server.
For Example:- xmlhttp onreadystatechange –
function ()
{
if (xmlhttp.readyState!)
{
document.getElementById ('test').innerHTML.xmlhttp.responseText.xmlhttp.open(GET, url, true)
exmlhttp.send(null)
}
}
Was this article: