Is there a clean, easy way to throw php exceptions through a json response jquery/ajax call.
If all the errors should be treated in the same way (showing a dialog for example). You can do it this way:
PHP End:
public function throwJsonException($msg) {
echo json_encode(array('error'=> true, 'msg' => $msg));
}
throwJsonException('login invalid!');
jQuery End:
$(document).ajaxSuccess(function(evt, request, settings){
var data=request.responseText;
if (data.length>0) {
var resp=$.parseJSON(data);
if (resp.error)
{
showDialog(resp.msg);
return;
}
}
});