Is there a clean, easy way to throw php exceptions through a json response jquery/ajax call.
Facebook do something in their PHP SDK where they throw an exception if a HTTP request failed for whatever reason. You could take this approach, and just return the error and exception details if an exception is thrown:
$results
));
}
catch (Exception $e) {
echo json_encode(array(
'error' => array(
'code' => $e->getCode(),
'message' => $e->getMessage()
)
));
}
You can then just listen for the error key in your AJAX calls in JavaScript: