As far as I know http redirects are handled entirely by the browser. So there is no way to detect a redirect if you don't have access to the backend.
When you are redirected to the login page it seems that your session is expired and you need to authenticate again.
You could create a function that sends the login information as soon as the login page is detected in the actual response.
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 );
}
});
}
Use the doRequset
to send your actual request. The success case checks if the response is the login page. If so, it sends the login request. When the login request is successful the doRequest function will be call again with its parameters.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…