Get only new rows on ajax refresh

Get only new rows on ajax refresh

benjiwbenjiw Posts: 10Questions: 1Answers: 0

I used DataTables as chat/communications platform of sorts. People post items into a MySQL database, and I use datatables to display the entries in a searchable, sortable format. I use the ajax function to check for new posts every minute or so. This works well, in general. However, the file that is being fetched (I store it in a cached JSON array in a text file) can be about 2-3MB. Obviously fetching this file every minute, for everyone using the site, is a bit taxing on the server.

Is there any way to only grab incremental rows for the table as opposed to downloading the entire file? Maybe this is an issue with my process that needs to be rethought, but just curious if anyone has encountered or accomplished something similar.

Thanks.

Answers

  • allanallan Posts: 63,498Questions: 1Answers: 10,471 Site admin

    Is there any way to only grab incremental rows for the table as opposed to downloading the entire file?

    Not built into DataTables, but the way I would do it myself is to include an id, hash, or some kind of token with each data request that the sever can use it identify the last row that the client knows about. Then when you make an Ajax query to get more data (to be added to the table using rows.add() you would pass that token and the server would be able to add that to the database query, thus giving you only the required rows - and that would work for all clients, regardless of their state.

    Allan

This discussion has been closed.