Save AJAX REQUESTS to run later

1

Use jQuery and the Ajax library to make REQUESTS.

There is a way to save REQUESTS, follow the example ..

The user is moving and suddenly the connection goes down and the user does not notice it. And he continues doing what he did .. and suddenly he sends a request, obviously this request will not be sent but how to save this request when the internet back it to be sent and the user does not lose its content ..

This REQUEST has to be saved and be immune to the page refresh, so even if it closes the page, when it returns the pending requests will be sent.

    
asked by anonymous 14.08.2015 / 14:16

1 answer

0

You can create log of your application, below an example of how to do this:

$(function() {

  $('#submit_button').on('click', function() {
    var data = {teste: 'teste'};
      $.ajax({
         url: "send_data.php",
         data: data,
         method: "POST",
         dataType: "json",
         beforeSend: function( data ) {
             $('#msg').html("enviando dados...");
         }
      }).done(function( data ) {
             var msg = $.parseJSON(data);
             $('#msg').html(msg);
      }).fail(function(error) {
         //redireciona e salva o log do erro
         window.location.href='event_log_register.php?data_expected=data:,' + 
         data.responseJSON +
         '&data_error=' +
         error.responseJSON +
         '&redirect=true';

      }).always(function() {
         $('#msg').html("Envio concluído!");
      });
   });
});

Copy and paste the text below into your browser:
data: application / octet-stream; base64, SGVsbG8 =

    
17.08.2015 / 18:59