views:

28

answers:

2

User opened two same URL in browser, if the user swithced to the edit mode of a data record in the first page but he also made an ajax call to delete the exact same db record in the other page and the data table also removed a row for that operation.

what should I do now, how can I synchronize the data between the two pages? or do I need to do something?

What's the best solution?

A: 

Sounds like you're looking for a Comet solution.

check out ape-project.org it's pretty new but looks easy(ish)

Jaimz
A: 

There are many approaches to solving this problem. They usually boil down to a question of how much state you maintain on the client side (that is, how much information does the client page have that it can include in any requests to the server).

One of the cleanest solutions is the one you see used here frequently as well as other major sites like Twitter. The client page asks the server every few seconds if the relevant records for the current page have changed (therefore the only state you need is the timestamp of when the page was last loaded). If so, you show the user some sort of prompt/error message indicating the page is out of date and that they should reload.

SO does this whenever an answer is posted while you are viewing the page. Twitter indicates when new tweets are available (for a given user or for a search).

Alternately, a more stateful approach is often used by much heavier ajax apps which will actually automatically load things like new comments or posts when they become available. This requires knowing more about what has already been loaded and what has not and where to put it in the page.

For resources that can be truly deleted, I generally prefer the first option but in many respects its a matter of preference.

Rob Van Dam