I want to be able to break out of my PHP script that is called with jQuery Ajax. How can I return an error back to jQuery to display to the user?
PHP:
if($gift_card != null)
{
echo "not null";
}
else
{
echo "null";
exit();
}
jQuery:
error: function(jqXHR, textStatus, errorThrown) {
status.html("There was an error processing the request. " + errorThrown);
setTimeout(function() {
status.fadeOut();
}, 4000);
},
success: function( data ) {
if (console && console.log){
console.log( 'Sample of data:', data);
}
status.html('Email Sent Successfully.');
setTimeout(function() {
status.fadeOut();
}, 4000);
If I echo null and exit, it is still coming back as success. Do I just have to check the data in success and see what is returned and then go from there?
if I am not mistaken, if your php header result code is anything other than 200 , it will be treated as an error by the jquery $.ajax .