English 中文(简体)
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

最佳回答

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.

问题回答

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.

I suggest Comet is not an overkill if "updates need to be constant." 15 seconds is very frequent; is your visited by many? Your server may be consumed serving these requests while starving others.

I don t know what your server-side data source looks like, or what kind of data you re serving, but one solution is to server your data with a timestamp, and send a timestamp of the last poll with every subsequent request.

  1. Poll the server, sending the timestamp of when the service was last polled (eg: lastPollTime).
  2. The server uses the timestamp to determine what data is new/updated and returns only that data (the delta), decreasing your transmission size and simplifying your client-side code.
  3. It may be empty, it may be a few cells, it may be the entire grid, but the client always updates data that is returned to it because it is already known to be new.

The benefits of this method are that it simplifies your client side code (which is less code for the client to load), and decreases your transmission size for subsequent polls that have no new data for the user.

Also, this allows you to maintain state on the server side because you don t have to save a state for each individual user. You just have one state, the state of the current data, that is differentiated by access time.

I think checking if there is any new data is a good option.

I would count the number of rows in the database and compare that with the number of rows in your (HTML) table. If they re not the same, get the difference in rows.

Say you got 12 table rows and there are 14 database rows as you check: Get the latest (14 - 12) = 2 rows.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签