要从$ .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!');}
}
我应该做什么呢?!
答案 0 :(得分:2)
返回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);
}
}