I'm post data to a php function using JSON post. I want to receive two different type of responses, success and error. For example, the following function:
function some_function(){
if ($error){
echo "some error";
exit;
} else {
echo "everything is ok"
exit;
}
}
In this case, both messages will be returned as success. How can I make the error message return to the error function in the ajax? Here's the ajax code:
jQuery.ajax({
url: '<?php echo $url; ?>',
data: response,
dataType: 'JSON',
type: 'POST',
success:function(data){
console.log(data);
},
error: function(data, errorThrown){
console.log(errorThrown);
}
});