Ajax (Asynchronous Java script And XML)
How Ajax Works
At the heart of Ajax is the ability to communicate with a Web server asynchronously without taking away the user’s ability to interact with the page. The XML HTTP Request is what makes this possible. Ajax makes it possible to update a page without a refresh. By Ajax, we can refresh a particular DOM object without refreshing the full page. Let’s see now what actually happens when a user submits a request:
- Web browser requests for the content of just the part of the page that it needs.
- Web server analyzes the received request and builds up an XML message which is then sent back to the Web browser.
- After the Web browser receives the XML message, it parses the message in order to update the content of that part of the page.
Steps of AJAX Operation
- A client event occurs.
- An XML HTTP Request object is created.
- The XML HTTP Request object is configured.
- The XML HTTP Request object makes an asynchronous request to the Webserver.
- The Webserver returns the result containing XML document.
- The XML HTTP Request object calls the callback() function and processes the result.
- The HTML DOM is updated.