考虑返回一个http状态为401,一个
JSON对象详细说明原因.如果你正在使用jQuery,那么你将会丢失你的error()回调,然后你可以解析你的对象.
$.ajax({
data: {},
dataType: 'html',
success: function(data) {
// do whatever here
},
type: 'POST',
url: 'myserver.com',
error: function(XMLHttpRequest, textStatus, errorThrown) {
// XMLHttpRequest.responseText has your json string
// XMLHttpRequest.status has the 401 status code
if (XMLHttpRequest.status === 401) {
location.href = 'login.php';
}
}
});
我不熟悉PHP,但这应该适用于任何环境.您可能必须禁止任何自动登录表单重定向.在asp.net mvc中,框架将看到401并将默认登录表单推回,状态为200.