What I want to do is alert() an error message to the user if my PHP script returns an error. Can someone tell me how to do this?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
EDIT:
So what i would do is simply use json and return a 200 response with a message for example
PHP
jQuery:
This way you can also display the errors for each field allowing the user to correct them. Youll probably need to modify my error message insertion but you get the idea.
Assuming you mean using
$.ajaxyou would simple assign an error function:However for the error function to be invoked the server must respond with 400 or 500 range error code. IF for example you are handling the errors in your php and then outputting an error message then presumable you would be sending a 200 response so the success function would still be invoked. You can manipulate this by setting the header manually with the php
header()function if you want.