0

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.

3 Answers 3

3

You should try PokeIn library. It helps you to notify connected clients based on server side events. Here is a basic scenario;

Single static timer runs on the server side and checks any changes on DB. If an update is available sends it to connected clients / associated groups etc.

Samples are available from

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.