AJAX 响应匹配任何状态
AJAX response match any status
我有以下代码:
$.ajax(
{
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
statusCode:
{
200: function( response )
{
},
401: function( response )
{
},
401: function( response )
{
},
}
}
);
我需要将回调设置为 'any' 状态,无论是 200 还是 404 我都需要它来触发相同的回调函数,如下所示:
$.ajax(
{
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
response = function( r )
{
alert('got ' + r.status);
}
}
);
我找到的最接近的解决方案是使用 success/fail,但我需要以某种方式将它们结合起来。有什么建议么?谢谢!
试试 complete
:
$.ajax({
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
complete: function( r ) {
alert('got ' + r.status);
}
}
);
我有以下代码:
$.ajax(
{
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
statusCode:
{
200: function( response )
{
},
401: function( response )
{
},
401: function( response )
{
},
}
}
);
我需要将回调设置为 'any' 状态,无论是 200 还是 404 我都需要它来触发相同的回调函数,如下所示:
$.ajax(
{
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
response = function( r )
{
alert('got ' + r.status);
}
}
);
我找到的最接近的解决方案是使用 success/fail,但我需要以某种方式将它们结合起来。有什么建议么?谢谢!
试试 complete
:
$.ajax({
url: "control/" + id + ".php",
data: $("auth-form").serialize(),
complete: function( r ) {
alert('got ' + r.status);
}
}
);