I am using jquery ajax to retrieve data from a php function.
My php function is as follows
<?php
if(isset($_GET['action'])) {
$data = array();
$data[0]["field"] = "data";
echo json_encode($data);
} else {
// error
return;
}
?>
and I am calling using the jquery ajax in my javascript
$.ajax({
url : '../functions/php/function.php',
type : 'GET',
dataType : 'json',
data : {'wrong','wrong'},
success : function(data) { console.log('all ok') },
error : function(log) { console.log('not ok') }
});
Instead of just returning from the php function with nothing is it possible to retrieve an error so that the jquery executes the error function?
2xxfrom your PHP code and theerrorhandler will execute