AJAX – JQuery – PHP – JSON – Get data from DB with AJAX

Some time ago I have made a simple ToDo list with PHP here. Today, using its database and one function from the list, I have decided to make the todo list with Ajax. This means, that you should not refresh the todo list once something is added to the database, but it asks the database permanently about some news.

Thus, what have I done? In order to demonstrate it a little better, the database is updated with one new entry every 5 seconds, adding the current date. If you leave the index.htm opened for 1 minute these are 12 new entries, so be careful 🙂

ajax41 ajax44

Now a little more explanation about the code:

The index.htm has the jQuery in it. It gets  JSON data from the php file every 5 seconds. In the PHP,  we do two things – we add a line with “addTodoItem” function and we return the data in the database with json encode.

Pretty much that is all. Here comes the code:

 

Available in GitHub!

Enjoy it! 😀

About

VBA Developer

Tagged with: , , ,