Question

I'm building a web app that uses ajax to communicate with the server. Basically, the user requests a record, it comes back in json, it's added to the DOM and the user makes changes to it. When the user requests the next record, the current record is stringified and sent back to the server and the following record comes back.

All this works really well.... as long as the user keeps requesting records. However, I am wondering how to handle the situation where the user stops his work: how do I get the last record updated?

I thought of adding the working record to the local storage while he's editing it and at each edit, updating the local storage and if he logs on next time and there's still a record in there, ajax it when he logs on. The problem with his approach is that if another user logs on to the same computer, then when that new user logs on, he's updating the data of another user.

I thought of using the window.unload event also; but that doesn't solve the problem of the user closing his browser before the final update.

What are some good ways to handle this issue. Thanks for your suggestions.

Was it helpful?

Solution

I would consider a 'draft-like' feature. Where you could upload changes after a certain amount of time of no input, for instance, after 15 seconds of no input, push those changes.

OTHER TIPS

If your app requires login, you could key the localStorage using their ids like so:

localStorage.getItem( "user13434" )

would retrieve data for user13434

localStorage.getItem( "user12345" )

would retrieve data for user12345

If the information is sensitive but not too sensitive you could add encryption, but it can be decrypted by experienced users which is why it must not be too sensitive.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top