AJAX and getting the latest entries in the database

I am working on a web application that will query the database for messages and display them in a browser. First of all, I get a list of message servers on the site, and then show the ones that are there. But then I want to use AJAX to periodically check messages and update the DOM with new ones.

However, I do not want to update the entire list. Just insert the most recent posts in the table. I use MySQL, PHP and mootools, and I really just want to hear best practice ideas on how to achieve this. Sending an array of each message identifier on the screen via AJAX and then comparing it with what is in the database is my current solution, but it seems extremely dirty.

Any suggestions are welcome.

+4
source share
1 answer

Perhaps instead of retrieving the entire message table from the database, instead, you can request the use of a timestamp as a way to receive only the most recent messages since the last check. All you have to do is keep a timestamp every time you run ajax check for new posts and query the database for posts> timestamp. Then verification is not required, you can simply add everything that is returned from the request to the browser list.

+3
source

All Articles