[英]Get http status code after ajax call
Im trying to get the http status code of my ajax call using the below code but the xhr.status is always undefined.. 我试图使用以下代码获取我的ajax调用的http状态代码,但xhr.status始终未定义。
function checksession() {
$.ajax({
type:'POST'
,url:'CheckSession'
,success: validateresult(session_ind)
,data: { antiCSRF : '{{acsrf}}',
session_id: '{{session_id}}'}
})
function validateresult(session_ind,xhr){
alert(xhr.status)
}
$.ajax({
//...
success: function(data, textStatus, xhr) {
console.log(xhr.status);
},
complete: function(xhr, textStatus) {
console.log(xhr.status);
},
error: function(xhr, textStatus , xhr) {
console.log(xhr.status);
}
});
or use : 或使用:
statusCode : An object of numeric HTTP codes and functions to be called when the response has the corresponding code. statusCode :一个数字HTTP代码对象,当响应具有相应代码时将调用该对象。 For example, the following will alert when the response status is a 404: 例如,以下内容将在响应状态为404时发出警报:
$.ajax({
statusCode: {
404: function() {
}
}
});
function checksession() {
$.ajax({
type:'POST'
,url:'CheckSession'
,success: validateresult(session_ind)
,data: { antiCSRF : '{{acsrf}}',
session_id: '{{session_id}}'}
success: function(data, textStatus, xhr) {
console.log(xhr.status);
},
complete: function(xhr, textStatus) {
console.log(xhr.status);
},
error: function(xhr, textStatus , xhr) {
console.log(xhr.status);
}
});
}
Does not appear that xhr
(or, jqxhr
below) was included as argument to validateresult
call , only session_ind
似乎没有包含xhr
(或下面的jqxhr
)作为validateresult
call的参数,仅session_ind
Try 尝试
function checksession() {
$.ajax({
type:'POST'
,url:'CheckSession'
,success: function (session_ind, textStatus, jqxhr) {
validateresult(session_ind, textStatus, jqxhr)
}
,data: { antiCSRF : '{{acsrf}}',
session_id: '{{session_id}}'}
});
function validateresult(session_ind, textStatus, jqxhr){
alert(jqxhr.status)
}
};
checksession();
jsfiddle http://jsfiddle.net/guest271314/nuukyLn0/ jsfiddle http://jsfiddle.net/guest271314/nuukyLn0/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.