Ext Js (4) - AJAX - Callback function on timeout?

I'd like to have a function which is called whenever an AJAX request times out, something like:

Ext.override(Ext.data.proxy.Ajax, {
    timeout: 60000,
    onTimeout: function () {
        alert("Sorry, the request timed out. Please try again.");
    }
});

Assuming a timeout would be handled as error/failure, I also tried this:

Ext.override(Ext.data.proxy.Ajax, {
    timeout: 60000,
    failure: function () {
        alert("Sorry, the request timed out. Please try again.");
    }
});

But seems like failure is only fired when an HTTP status code was returned (and was not equal to 200).

I really searched the internet for a solution, but there seems to be nothing like an onTimeout or onCancel.

Any suggestions on this, how I can implement such a global function?

Upvotes: 2

Views: 1400

Answers (1)

Greendrake
Greendrake

Reputation: 3734

Use exception listener and check for request status equal to 0:

proxy: {
    type: 'ajax',
    // ....
    listeners: {
        'exception': function(proxy, request) {
            if (request.status === 0) {
                timeoutCallback();
            }
        }
    }
}

Example: https://fiddle.sencha.com/#fiddle/qt7

Upvotes: 2

Related Questions