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 XMLHttpRequest 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 XMLHttpRequest object is created.
- The XMLHttpRequest object is configured.
- The XMLHttpRequest object makes an asynchronous request to the Webserver.
- The Webserver returns the result containing XML document.
- The XMLHttpRequest object calls the callback() function and processes the result.
- The HTML DOM is updated.