Ajax错误:200响应代码

时间:2013-09-04 18:04:21

标签: jquery ajax json

我正在使用jQuery Form插件来处理使用Ajax的表单提交:

$('.login-form').ajaxForm({
    dataType: 'json',
    success: function(data){
        console.log('Success!');
        console.log(data);
    },
    error: function(data){
        console.log('There was an error:');
        console.log(data);
    }
})

提交后,ajax返回状态为“200”的错误。这是JSON格式的响应:

{
    "success": false, 
    "heading": "The following errors were encountered", 
    "message": "<ul><li>The existing username and/or password you submitted are not valid</li></ul>"
}

我通过jsonlint.com运行了它,它返回为有效。

在Chrome的“网络”标签中,响应将返回application/json类型。

那么为什么ajax会返回“错误”而非“成功”?

jQuery 1.9.1

1 个答案:

答案 0 :(得分:1)

JSON message键的值在其中有换行符,由于某种原因导致错误:

{
    "success": false, 
    "heading": "The following errors were encountered", 
    "message": "<ul><li>The existing username and/or password you submitted are not valid</li>
</ul>"
}

我不认为字符串中的换行符很重要,但我猜他们会这样做......

相关问题