Posted by mtwinkle on April 12, 2007
Typical scenario –> Create a HTML form with some input fields and submit button. User enters the info and clicks submit. The information is sent to the server using ‘GET’ or ‘POST’, server responds, and then the results are displayed in the new page.
No need of submit button to send the data to the server. Also, the whole page need not be refreshed and the result can be displayed on the same page itself.
The XMLHttpRequest object has a special property called onreadystatechange. onreadystatechange stores the function that will process the response from the server.
Every time the “ready state” changes this function will be executed.
What is this “ready state”?
The XMLHttpRequest object has another property called readyState. This is where the status of our server’s response is stored. The response can be processing, downloading or completed. Each time the readyState changes then our onreadystatechange function executes.
readyState is 4 that means the response is complete.
The property that stores the server’s response, responseText.
Technologies used by AJAX:
2. DOM – for accessing and manipulating the structure of the HTML of the page
3. XML – represents the data passed between the server and client.
4. XMLHttpRequest – object for asynchronously exchanging the XML data between the client and the server.
Should I use an HTTP GET or POST for my AJAX calls?
AJAX requests should use an HTTP GET request when retrieving data where the data will not change for a given request URL. An HTTP POST should be used when state is updated on the server.