Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ajax data update. Extjs

I need to keep certain data ( in a grid) up to date and was gonna do a poll to the server every 15 seocnds or so to get the data and refresh the grid, however it feels a bit dirty ( the grid will have the loading icon every 15 sec..) doesnt look great...
Another option is to check if there is new data and compare the new data with the current data and only refresh the grid if there is any changes ( I would have to do this client side tho because maintaing the current state of every logged in user also seems like an overkill)
I m sure there are better solutions and would love to hear about them

I heard about COMET, but tit seems to be a bit of an overkill
BTW i m using asp.net MVC on the server side

I d like to hear what people have to say for or against continuos polling with js Cheers

like image 286
roundcrisis Avatar asked Feb 06 '26 06:02

roundcrisis


2 Answers

Sounds like COMET is indeed the solution you're looking for. In that scenario, you don't need to poll, nor do comparisons, as you can push out only the "relevant" changed data to your grid.

Check out WebSync, it's a nice comet server for .NET that'll let you do exactly what you've described.

Here's a demo using ExtJS and ASP.NET that pushes a continuous stream of stock ticker updates. The demo is a little more than you need, but the principal is identical.

like image 119
jvenema Avatar answered Feb 07 '26 20:02

jvenema


Every time you get the answer from the server, check if something has changed.

Do a request. Do let the user know that you are working with some spinner, don't hide it. Schedule the next request in 15 seconds. The next request executes; if nothing has changed, schedule the next one in 15 + 5 seconds. The next request executes; if nothing has changed, schedule the next on in 15 +5 +5 seconds. And so on. The next request executes; if something has indeed changed, reset the interval to 15 seconds.

Prototype can do this semi-automatically with Ajax.PeriodicalUpdater but you probably need stuff that is more customized to your needs.

Anyway, just an idea.


As for continuous polling in general; it's bad only if you hit a different site (using a PHP "bridge" or something like that). If you're using your own resources you just have to make sure you don't deplete them. Set decent intervals with a decay.

like image 45
Kaze no Koe Avatar answered Feb 07 '26 19:02

Kaze no Koe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!