jquery ajax成功-是否可以返回JSON而不是字符串?
要从$.ajax调用返回错误,必须有比在ajax.php文件中回显错误然后对其进行修剪更好的方法 这看起来非常笨拙,而且非常健壮:jquery ajax成功-是否可以返回JSON而不是字符串?,jquery,ajax,Jquery,Ajax,要从$.ajax调用返回错误,必须有比在ajax.php文件中回显错误然后对其进行修剪更好的方法 这看起来非常笨拙,而且非常健壮: success: function(e){ var e = trim(e); if(e == 'SUCCESS') {alert('your password has been changed!');} if(e == 'ERROR1') {alert('please fill in all input
success: function(e){
var e = trim(e);
if(e == 'SUCCESS')
{alert('your password has been changed!');}
if(e == 'ERROR1')
{alert('please fill in all inputs!');}
if(e == 'ERROR2')
{alert('password incorrect!');}
if(e == 'ERROR3')
{alert('change failed!');}
}
我该怎么办 返回JSON:
{ success: false, errorMessage: 'please fill in all inputs!' }
然后:
success: function(e) {
if(e.success) {
alert('your password has been changed!');
}
else {
alert(e.errorMessage);
}
}
啊,太酷了,所以我可以在ajax.php文件上回显/json_encode insome脚本标记?