Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

AJAX instance


May 08, 2021 AJAX


Table of contents


AJAX instance


AJAX works like an intermediate tier (AJAX engine) between the user and the server, asynchronousing user actions from the server response.

To help you understand how AJAX works, we created a small AJAX application:

Use AJAX to modify this text content


Try it out . . .

AJAX instance resolution


The AJAX application above contains a div and a button.

The div section is used to display information from the server. When a button is clicked, it is responsible for calling a function called loadXMLDoc():

<!DOCTYPE html>      
<html> <body>       
<div id="myDiv"><h2>Let AJAX change this text</h2></div>        
<button type="button" onclick="loadXMLDoc()">Change Content</button>        
</body>        
</html>

Next, add a hashtag to the head section of the page. This loadXMLDoc() function is included in the label:

<head>        
<script>        
function loadXMLDoc()
{        
.... AJAX script goes here ...        
}        
</script>        
</head>

To create AJAX instances, you need to use server-side languages such as Servlet, JSP, PHP, ASP.Net, etc., and here we use JSP.

To create an instance of AJAX:

  1. Load the org.json .jar file
  2. Create an input page to receive any text or numbers
  3. Create a server-side page to process requests
  4. Provide an .xml the web file

The difference between AJAX and traditional CGI programs


When you try the AJAX sample, there is no discontinuity and you can get a response very quickly, but when you try the standard GCI sample, you will have to wait for the response and your page will be refreshed.

In the next chapter, we'll continue to explain how AJAX works.