views:

56

answers:

2

I would like to have a page that checks for updates to a database table and refreshes the grid using an Ajax call and when a new row is inserted into the table pop up a message window.

This database table gets updated with new rows every 15 minutes or so and the message window lets the user know that a new record has been added or possibly more than one record.

I'm wanting to do this in ASP.NET MVC with Ajax but have no idea how to go about setting up the javascript to check for updates on a timer or if there's a flag that the XHR uses to indicate a change in state.

+1  A: 

This could be a possible way to do it:

  1. Store the time when the data is aquired in a global variable in javascript.

  2. Every x minutes, you do a javascript call to an action method with the timestamp as parameter. This can be done for example using the jQuery Timer as suggested by Rony.

  3. The action method checks the database to see if anything has changed or not, and returns a simple boolean 1/0.

  4. If, and only if, the data has changed, you get the new data from another action method and notify the user that new data has been retrieved.

Tomas Lycken
I'll try this out. Thanks.
kntcnrg
A: 

you can use jQuery timers to check the state of the database using ajax and then modify the values in the table accordinly

Rony