Ankur Raiyani
Ankur Raiyani

Reputation: 1708

jQuery Mobile Store data locally and sync when internet is available

I am beginner in jQuery Mobile. I have a simple form which has 10 fields.

My requirement is, when user submit this form check for internet connection if it's available then store the data in DB else store data locally. Whenever internet connection is available sync those data and upload to server.

how can i achieve this? Please guide me.

Thanks

Upvotes: 0

Views: 638

Answers (1)

Ken Herbert
Ken Herbert

Reputation: 5236

One way to implement this is to use a standard jQuery ajax call to the database.

If it returns an error (which would, among other things, indicate that an internet connection may not be available) copy or move the data (depending on what you need) to an array specifically used as a pending upload queue.

Then have a function running via setInterval to check if there is data in the pending upload queue, if there is try to upload it, if it succeeds remove the uploaded data from the queue. If it fails leave the data for the next try.

Upvotes: 2

Related Questions