Answer the question
In order to leave comments, you need to log in
How to implement delayed data upload to the server from phonegap?
There is one one-page js application in which everything works via ajax. Loading from the database data occurs as it is used with the system. How to correctly implement the upload of data to the server if the connection can be lost for a long time? The whole system has already been written and successfully sends data to the server with ajax requests, in case of a connection failure it writes an error.
The following comes to mind:
1) Set an infinite send timeout. There is a big problem here - if the phone is rebooted, then the session can no longer be restored. Some kind of buffer zone is needed.
2) Send ajax requests directly when there is a connection, and when there is no connection, turn on a special offline mode (recoloring the background in red), and then somehow interrupt the ajax request by sending data to some buffer zone, data from which they would have started, how the device would connect to the server.
How to competently implement a buffer zone on ready-made ajax requests?
Thanks for understanding. The question may seem silly to some, but still.
Answer the question
In order to leave comments, you need to log in
Usually this is solved by accumulating requests in the local storage, and then sending them to the server (preferably a group one).
In your case, you need to make a layer service between Ajax and the application that will receive requests to send and:
- Check if there is a network
- If there is a network -> send a request
- If there is no network -> save the request data in localStorage
By timer, or at any time another event, you can check whether there is pending data in localStorage, and send them to the server (immediately in a bunch).
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question