HubSpot / messenger

Growl-style alerts and messages for your app. #hubspot-open-source
http://github.hubspot.com/messenger/
MIT License
4.02k stars 406 forks source link

Keep ajax request running if client get disconnected for a few seconds #112

Open misner opened 8 years ago

misner commented 8 years ago

I am using ajax:

var msg;
msg = Messenger().run({
  action: $.ajax,
  progressMessage:  'Loading the RESULT...',
  successMessage:  'This is the Result : %{results  and all}',
   actions: {
      getMoreDetails: {
        label: "give me details on the provided result",
        action: function() {
          ....//do stuff
        }
      },
      goToNextResult: {
        label: 'Move To Next Result',
        action: function(){
         //do stuff
        }       
      }
    }
});

So the user while online clicks a button and a modal appears with the message 'Loading the Result'.

Then if for any reason, the user's mobile loses internet connection (can happen often...ex: subway tunnel :) instead of trying to maintain the request (at last a few seconds to see if user might gets re-connected again), the modal disappears of the screen.

On console I see the error: GET http://localhost:3000/deals/deal5/ net::ERR_INTERNET_DISCONNECTED

How can I do the following: online user triggers ajax request then his device gets disconnected but the modal stays on the screen (for max 10 seconds) and then display results if it gets it within the 10 sec. If not it show a message like 'osrry we did not get the results, check your internet connection' ?

Can I do it with Messenger or do I need to use add offline.js (also by hubspot) to messenger.js and coordinate the two ?