服务器端:
....
$_SESSION['accountId'] = $accountId;
$_SESSION['type'] = $_POST['accountType'];
echo '1';
return;
客户端:
$.ajax(
{
type:'POST',
data: $("#flowFormSubmit").serialize(),
dataType:'text/plain',
timeout:1000,
success:function(response){
if(-1 == response)
alert('fail');
else
alert('succeed');
}
});
我已经测试过它会在“返回”处停止; 什么情况下success函数不会被调用?
编辑:
添加错误回调后,捕获到了,但还没有输出有用的信息:
error:function(response){ alert(response);alert(response.statusText); },
它仅输出:
[object XMLHttpRequest]
OK
为什么会陷入错误回调?
最佳答案
错误回调还有更多有用的参数。尝试获取 textStatus。
error: function(XHR, textStatus, errorThrown) { console.log(textStatus); }
检查那是什么。
一个快速猜测是您打算使用dataType: 'text'
而不是'text/plain'
。 (Check documentation)
$.ajax({
type:'POST',
data: $("#flowFormSubmit").serialize(),
dataType:'text',
timeout:1000,
success:function(response){
if(-1 == response)
alert('fail');
else
alert('succeed');
}
});
关于jquery - response.statusText ="OK"但陷入 ajax 与 jQuery 的错误回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1414205/