HTML5 - synchronize local DB with Server
I have an application which runs in ofline mode also using browsers local database. Now I want my application to sync this with my server. I want to perform the below tasks
- Check for a connection at regular intervals
- When I开发者_开发百科 have a connection send data to the server
- Get the updated data present on the server.
What should I do to accomplish my above goals?
Is WebSockets a solution to it?
You do not need WebSockets for this. I would suggest simply using XMLHttpRequest. You do need to keep track of what local data is un-synced to the server (either by placing references to un-synced data in a special "queue" when offline or by having a separate field in the local DB saying "synced"). When connected, read unsynced data and submit by XMLHttpRequest.
精彩评论