[fw-general] How to display errors when an ajax request fail?

2009-10-28 Thread Juan Felipe Alvarez Saldarriaga
Hey.

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?.

Thanks.


Re: [fw-general] How to display errors when an ajax request fail?

2009-10-28 Thread drm

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


Re: [fw-general] How to display errors when an ajax request fail?

2009-10-28 Thread Саша Стаменковић
If you send header HTTP code 500 from your controller

$this-getResponse()-setHttpResponseCode(500);

you can catch it in your javascript with

$.ajax({
type: 'POST',
url: '/c/a',
data: $('#form').serialize(),
dataType: 'html',
success: function(response) {
// success code
},
error: function() {
// error code - show some red div or alert or...
}
});

Regards,
Saša Stamenković


On Wed, Oct 28, 2009 at 2:29 PM, drm d...@melp.nl wrote:

 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