Implement AJAX in an application
I will start with a brief introduction of Ajax.
Web pages become more responsive using Ajax by exchanging data with the web server behind the scenes, instead of reloading an entire web page each time a user makes a change. In simple words, we can say that Ajax is used to asynchronously get the information from the server and update only that area of the web page where this information fetched needs to be displayed, avoiding refresh of the entire page.
From the above diagram, we can summarize the steps to send an asynchronous call to the server.
2. An XMLHttpRequest object is created and configured.
3. An XMLHttpRequest makes a call.
4. The web server will exchange the data from the data stores.
5. Response is received from the web server and we can further handle the response accordingly.
Now, we will go with the details of this with the help of a simple application.
Step 1 : Create an HTML page with the following code
In this step, we have to create and configure the XMLHttpRequest object.
The XMLHttpRequest object is used to exchange data with a server behind the scenes. XMLHttpRequest object can be implemented in two ways, ActiveXObject is Internet Explorer specific, and XMLHttpRequest works with other browsers. So a check is made before creating the object, like this,
Now write another function to execute the XMLHttpRequest object
1: server connection established
2: request received
3: processing request
4: request finished and response is ready
robust and secure than GET