Detect slow internet connection in phonegap application

I can check When my telephone application does not have Internet using navigator.network.connection.type , but when the connection is slow (almost none), how can I check if this situation is detected using any jquery / javascript code ??

+4
source share
1 answer

You can use setTimeout() to set the maximum time for the request:

 var timeout; var xhr = $.ajax({ type: "GET", url: "http://myservice.com/jsonp", data: data, success: function(msg){ // All went OK if(timeout != null) clearTimeout(timeout); } }); timeout = setTimeout(function() { // Request took >= 10 seconds // We could kill it? xhr.abort(); // Or send a message to the user and ask whether they want to continue if(!confirm("Network connection is taking longer than usual to complete. Continue waiting?")) { xhr.abort(); } }, 10000); 
+2
source

All Articles