據我所知,http重定向完全由瀏覽器處理。因此,如果您無權訪問後端,則無法檢測到重定向。
當您重定向到登錄頁面時,您的會話似乎已過期,您需要再次進行身份驗證。
您可以創建一個函數,在實際響應中檢測到登錄頁面後立即發送登錄信息。
sendLogin: function (params, successCallback, failureCallback, scope) {
Ext.Ajax.request({
url: "loginurl",
params: params,
success: function (response, options) {
successCallback.call(scope || this, response, options);
},
failure: function (response, options) {
failureCallback.call(scope || this, response, options);
}
});
}
doRequest: function (params, successCalback, failureCallback, scope) {
var me = this;
Ext.Ajax.request({
url: "someurl",
success: function (response, options) {
if (isLoginPage(response)) {
this.sendLogin(
loginParams,
function (successResponse, successOptions) {
me.doRequest(params, successCallback, failureCallback, scope);
},
function (failureResponse, failureOptions) {
failureCallback.call(scope || this, failureResponse, failureOptions);
},
me
);
} else {
successCallback.call(scope || this, response, options);
}
},
failure: function (response, options) {
failureCallback.call (scope || this, response, options);
}
});
}
使用doRequset
發送您的實際請求。成功案例檢查響應是否爲登錄頁面。如果是這樣,它發送登錄請求。當登錄請求成功時,doRequest函數將再次調用其參數。