AJAX is used to create more interactive applications.
The Below example will demonstrate how a web page can communicate with a web server while a user type characters in an input field:
Start typing a name in the input field below:
Suggestions:
When a user types a character in the input field above, the function "showHint()" is executed. The function is triggered by the "onkeyup" event:
Source code explanation:
If the input field is empty (str.length==0), the function clears Content of the txtHint placeholder and exits the function.
If the input field is not empty, the showHint() function executes the following:
The page on the server called by the JavaScript above is an ASP file called "gethint.html".
Below we have created two versions of the server file, one written in ASP and one in PHP.
The source code in "gethint.html" checks an array of names, and returns the corresponding name(s) to the browser:
Below is the code above rewritten in PHP.
Note: To run the example in PHP, change the value of the url variable (in the HTML file) from "gethint.html" to "gethint.html".
Your Query was successfully sent!