2010-05-17 6 views
0

$ .ajax 호출에서 오류를 반환하려면 ajax.php 파일에 오류를 표시 한 다음 트리밍하는 것이 좋습니다. 내가 대신 무슨 일을해야jquery ajax sucess - 문자열 대신 JSON을 반환 할 수 있습니까?

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!');} 
} 

! :

이 매우 서투른과의-강력한 보인다

답변

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); 
    } 
} 
+0

멋진 아, 그래서 난 그냥 ajax.php 파일에 스크립트 태그 insome /로 json_encode을 에코 할 수 있습니까? – Haroldo

관련 문제