kntcnrg
kntcnrg

Reputation: 601

ASP.NET MVC Ajax

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.

Upvotes: 0

Views: 268

Answers (3)

Mani
Mani

Reputation: 51

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

Upvotes: 3

Rony
Rony

Reputation: 9511

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

Upvotes: 0

Tomas Aschan
Tomas Aschan

Reputation: 60674

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.

Upvotes: 1

Related Questions