PDA

View Full Version : Cancel Remote Requests when no Internet Connection detected



sandeep45
13 Sep 2011, 6:40 AM
I would like to cancel all Ajax requests when the user looses Internet Connection. In an attempt do do so, I have the following code:



Ext.data.Connection.on('beforerequest', function(con, options) {
console.log('Ajax request made to ' + options.url);
if(window.navigator.onLine === false){
alert("there is no internet, will stop request right here");
con.abort(con.request);
}
});


This code prevents the request from being made, but I get the following script error:


Uncaught TypeError: Cannot read property 'readyState' of undefined

The error comes from the following code in sencha-touch-debug-w-comments.js:27627 (http://sandeep.assistly.local:3000/mobile/touch/sencha-touch-debug-w-comments.js?1315593257)



isLoading : function(r) {
// if there is a connection and readyState is not 0 or 4
return r && !{0:true, 4:true}[r.xhr.readyState];
},


What i would like is to abort/cancel the connection gracefully and for stores/models, fire an exception on their proxies and for ajax requests fire the failure/callback method defined in them.

Thank You