Juan Felipe Alvarez Saldarriaga wrote:
I'm using the default ErrorController from Zend_Tool, so, when an
error is thrown setHttpResponseCode sets an error 500, how can I catch
the exception message on javascript? how can I set the exception
message into the response object? there's not setMessage method in
Zend_Http_Response :| how can I achive this? I'm using jQuery to catch
errors, using $.ajaxSetup( { error: function( XMLHttpRequest,
textStatus, errorThrown ) {} } ); XMLHttpRequest.statusText has the
default error message "Internal Server Error" from Zend_Http_Response,
there's a way to change this message with the exception message?.
Though strictly not a Zend Framework question but more a jQuery one, you
can just read out the responseText property of the XMLHttpRequest. Try
this snippet:
<?php
if(count($_GET)) {
Header("HTTP/1.1 500 Internal server error");
echo "Sorry, error!";
die();
}
?>
<script type="text/javascript" src="javascript/jquery.js"></script>
<script type="text/javascript">
$(function(){
$.ajaxSetup({
error: function(req) {
alert("Error " + req.responseText);
}
});
$('input').click(function(){
$.get('<?php echo $_SERVER['PHP_SELF']?>', {test: 'w00t'},
function(data){
alert(data);
});
});
});
</script>
<input type="button" value="click me">