Jquery Ajax错误:200响应代码
我正在使用该插件处理Ajax表单提交:Jquery Ajax错误:200响应代码,jquery,ajax,json,Jquery,Ajax,Json,我正在使用该插件处理Ajax表单提交: $('.login-form').ajaxForm({ dataType: 'json', success: function(data){ console.log('Success!'); console.log(data); }, error: function(data){ console.log('There was an error:'); conso
$('.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>"
}
{
“成功”:错误,
“标题”:“遇到以下错误”,
“消息”:“- 您提交的现有用户名和/或密码无效”
}
我查了一遍,结果证明是有效的
在Chrome的网络选项卡中,响应返回为typeapplication/json
那么为什么ajax返回的是“错误”而不是“成功”
jQuery 1.9.1JSON
消息
键的值中有一个换行符,由于某种原因导致了错误:
{
"success": false,
"heading": "The following errors were encountered",
"message": "<ul><li>The existing username and/or password you submitted are not valid</li>
</ul>"
}
{
“成功”:错误,
“标题”:“遇到以下错误”,
“消息”:“- 您提交的现有用户名和/或密码无效
”
}
我认为字符串中的换行符并不重要,但我想它们是重要的…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>"
}
{
“成功”:错误,
“标题”:“遇到以下错误”,
“消息”:“- 您提交的现有用户名和/或密码无效
”
}
我不认为字符串中的换行符有什么关系,但我想它们有什么关系…问题是什么?它在做什么是您不期望的?
console.log(data.responseText)
某些服务已损坏,并且不使用状态代码显示错误状态。在我看来,您只需要检查success
键。确保EE将模板类型设置为JavaScript(假设响应在模板中)@BarbaraLaird它返回的是Ajax“错误”而不是Ajax“成功”(请注意,Ajax“成功”与JSON响应中的“成功”值不同).有什么问题吗?它在做什么是您不期望的?console.log(data.responseText)
某些服务已损坏,并且不使用状态代码显示错误状态。在我看来,您只需要检查success
键。确保EE将模板类型设置为JavaScript(假设响应在模板中)@BarbaraLaird它返回的是Ajax“错误”而不是Ajax“成功”(请注意Ajax“成功”与JSON响应中的“成功”值不同)。