response.statusText ="确定]但落入错误回调从阿贾克斯与jQuery [英] response.statusText="OK" but falls into error callback from ajax with jQuery

查看:148
本文介绍了response.statusText ="确定]但落入错误回调从阿贾克斯与jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器端:

 ....
    $_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');
    }
});

我测试过,它就停在回归; 在什么情况下会成功的功能不会被调用?

I've tested that it stops right at 'return;' Under what conditions will success function not be called?

修改

添加错误回调后,它抓住了,但没有输出有用的信息尚未:

after adding error callback,it's caught,but didn't output useful information yet:

error:function(response){ alert(response);alert(response.statusText); },

这只能输出:

It outputs only:

[object XMLHttpRequest]  
OK

为什么会陷入错误回调?

Why does it fall in error callback?

推荐答案

有更多有用的参数错误回调。尝试获得了textStatus。

There are more useful parameters to the error callback. Try getting the textStatus.

error: function(XHR, textStatus, errorThrown) { console.log(textStatus); }

检查是什么。

Check what that is.

一个快速的猜测是,你的意思是使用数据类型:文本不是text / plain的。 (检查文档

A quick guess is that you meant to use dataType: 'text' not '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');
    }
});

这篇关于response.statusText ="确定]但落入错误回调从阿贾克斯与jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆