Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jquery ajax成功-是否可以返回JSON而不是字符串?_Jquery_Ajax - Fatal编程技术网

jquery ajax成功-是否可以返回JSON而不是字符串?

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

要从$.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 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脚本标记?