我在服务器端设置HTTP状态代码值,并尝试从调用jQuery Ajax方法读取此值。我强制返回状态代码401. Chrome显示HTTP状态代码0;而FF,IE和Safari显示预期的HTTP状态代码为401。
jQuery Ajax Call:
/* change password */
var reqEmail = "?Email=" + getURLParameter('email');
var reqToken = "&ResetToken=" + getURLParameter('token');
var reqPassword = '&Password=' + password;
var reqPath = '../ws/visitor/SetPassword' + reqEmail + reqPassword + reqToken;
$.ajax({
type: "POST",
url: reqPath,
contentType: "application/json; charset=utf-8",
dataType: "json",
cache: false,
complete: function (xhr) {
console.log("Status: " + xhr.status);
console.log("StatusText: " + xhr.statusText);
}
});
Fiddler捕获的反应:
HTTP/1.1 401 Unauthorized
Cache-Control: private
Transfer-Encoding: chunked
Content-Type: application/json
Server: Microsoft-IIS/7.5
Date: Tue, 22 Oct 2013 19:03:34 GMT
Chrome控制台日志:
Status: 0
StatusText: error
FireFox控制台日志:
Status: 401
StatusText: Unauthorized
C#设置HTTP状态代码:
HttpContext.Current.Response.StatusCode = 401;
HttpContext.Current.Response.TrySkipIisCustomErrors = true;
HttpContext.Current.Response.ContentType = "application/json";
HttpContext.Current.Response.End();
同时
当我将HttpContext.Current.Response.StatusCode设置为等于该值时,Chrome将显示以下状态代码:204,205,304。
有没有人知道为什么我在浏览Chrome中的HTTP状态代码时遇到问题?
提前致谢。