AJAX Database Operations - AJAX

How easy it is to access information from a database using AJAX?

To clearly illustrate how easy it is to access information from a database using AJAX, we are going to build MySQL queries on the fly and display the results on "ajax.html". But before we proceed, let us do the ground work. Create a table using the following command.

NOTE: We are assuming you have sufficient privilege to perform the following MySQL operations

Now dump the following data into this table using the following SQL statements:


Client Side HTML File

Now let us have our client side HTML file, which is ajax.html, and it will have the following code:

NOTE: The way of passing variables in the Query is according to HTTP standard and have formA.

The above code will give you a screen as given below:

NOTE: This is dummy screen and would not work

Your result will display here in this section after you have made your entry.

Server Side PHP File

Your client-side script is ready. Now, we have to write our server-side script, which will fetch age, wpm, and sex from the database and will send it back to the client. Put the following code into the file "ajax-example.php".

Now try by entering a valid value (e.g., 120) in Max Age or any other box and then click Query MySQL button.

Your result will display here in this section after you have made your entry.

If you have successfully completed this lesson, then you know how to use MySQL, PHP, HTML, and Javascript in tandem to write AJAX applications.

All rights reserved © 2020 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

AJAX Topics