I have a php script which returns either a success or error. the success actually returns an empty array, but it allows the success calls in javascript to occur.
I know that i can use a header to do errors, such that the error will fire, but how do i return it custom strings?
example of success:
header("Content-Type: application/json");
echo json_encode(array());
Example of error i was trying.:
header("Wrong Pasword.", true, 400);
echo "Wrong Password.";
Neither the first arg of header nor the echo is returned to the client side. I am trying to return a custom error so that way i can, in javascript say:
$.ajax({
url:"script.php",
success:function(){},
error: function(error){
alert(error);
}});
in this sample, i was trying to have error be: "Wrong Password."
errorin your ajax call should be used for things like server errors, 404's, etc. Thesuccessfunction does not mean that the action you are performing is necessarily successful, but that the request was successful, if that makes sense. In your json include all information, such as whether the action was performed, data returned or any error messages, etc. This is not what the http headers are for.header("HTTP/1.0 400 Bad Request"); echo "Wrong Password."; return;and it will return i believe what works.