简体   繁体   English

Ajax错误:200响应码

[英]Ajax Error: 200 Response Code

I'm using the jQuery Form plugin to handle a form submission with Ajax: 我正在使用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);
    }
})

After submission, the ajax returns an error with a status of "200". 提交后,ajax返回状态为“ 200”的错误。 This is the JSON-formatted response: 这是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>"
}

I ran that through jsonlint.com , and it returned as valid. 我通过jsonlint.com进行了运行,它返回为有效。

In Chrome's Network tab, the response is returned as type application/json . 在Chrome的“网络”标签中,响应以application/json类型application/json

So why is ajax returning "error" rather than "success"? 那么,为什么ajax返回“错误”而不是“成功”?

jQuery 1.9.1 jQuery 1.9.1

The value of the JSON message key had a line break inside it, which for some reason caused an error: 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>"
}

I wouldn't think line breaks inside a string would matter, but I guess they do... 我不认为字符串中的换行符很重要,但我想它们确实可以...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM