I’ve been searching for a simple, clean and flexible way to return errors to the browser after a POST or GET request.
Example AJAX request with jQuery:
$.ajax({
data : {
method : 'example',
input : 1
},
success : function(i){
if(i != 'succes'){
alert(i);
}
}
});
Server side response:
switch($_POST['method']){
case 'example':
if($_POST['input'] == 1) {
echo 'succes';
} else {
echo 'error';
// or
die('error');
}
break;
}
This just doesn’t feel solid enough. Does anyone know a good way to capture an error combined with a message?
@Esailija is correct; return HTTP status codes so that jQuery’s ajax error handler can receive the error.