0

To return an error from a $.ajax call, there's gotta be a better way than echoing an error in the ajax.php file and then trimming it!

this seems very clumsy and in-robust:

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

what should i be doing instead?!

1 Answer 1

2

return JSON:

{ success: false, errorMessage: 'please fill in all inputs!' }

and then:

success: function(e) {
    if(e.success) {
        alert('your password has been changed!');
    }
    else {
        alert(e.errorMessage);
    } 
} 
Sign up to request clarification or add additional context in comments.

1 Comment

ah cool, so i can just echo out / json_encode insome script tags on the ajax.php file?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.