我想要一个在 AJAX 请求超时时调用的函数,例如:
Ext.override(Ext.data.proxy.Ajax, {
timeout: 60000,
onTimeout: function () {
alert("Sorry, the request timed out. Please try again.");
}
});
假设超时将被处理为错误/失败,我也尝试过:
Ext.override(Ext.data.proxy.Ajax, {
timeout: 60000,
failure: function () {
alert("Sorry, the request timed out. Please try again.");
}
});
但似乎 failure
仅在返回 HTTP 状态代码(且不等于 200)时才会触发。
我确实在互联网上搜索了解决方案,但似乎没有像 onTimeout
或 onCancel
这样的东西。
对此有何建议,我如何实现这样的全局功能?
最佳答案
使用exception
监听器并检查请求状态是否等于 0:
proxy: {
type: 'ajax',
// ....
listeners: {
'exception': function(proxy, request) {
if (request.status === 0) {
timeoutCallback();
}
}
}
}
关于extjs - Ext Js (4) - AJAX - 超时回调函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31561211/