2
Use jQuery and the Ajax library to make REQUESTS.
There is a way to save REQUESTS, follow the example..
The user is there moving and suddenly the connection drops and the user does not notice it. And continues doing what he did.. and suddenly it sends a request, obvious this request will not be sent but how to save this request for when the internet comes back it is sent and the user does not lose its content..
This REQUEST has to be saved and immune to page refresh, so that even if it closes the page, when it returns the pending requests will be sent.
friend, it is even possible to do this with
localStorage
, you could do a wrapper for the call$.ajax
withtimeout
, and in theerror
of$.ajax
you would put the request in afila
in thelocalStorage
, then you would have awindow.setInterval
reading thisfila
and resending therequest
, but I’ll tell you right away that this approach will bring you more problems than benefits.– Tobias Mesquita
@Tobymosque why it would cause more errors than solutions ?
– Vinícius Lara
Imagine a problem the transport channel on the return of the request, to the server everything is ok, but the browser received no response, so in this case you would forward the request. this may end up generating data duplicity, another point, the user sends a form, gave timeout, but as you put the request in the pool you gave the user a "OK" message, however before the connection was reestablished the user cleaned the localStorage, then we have a success message in an error scenario.
– Tobias Mesquita
then perhaps it is better, just report an error in communication, then the user can perform some query in the system or resend the data.
– Tobias Mesquita
@Tobymosque I understand, but this page would be for offline use (Manifest cache) so that would be essential.. I will try to think of something.
– Vinícius Lara
In this case, I think the ideal would be to develop a Chrome app, I believe this way you can use a sqlite database, then you would have a "service" doing the data synchronization when the connection is available.
– Tobias Mesquita
if it’s not a large amount of data, you can save it to cookies.. Another place to save is localstorage, but available in browsers with newer versions only.
– Daniel Omine