Re: Ajax Errors

2009-08-11 Thread Tony Thomas

I actually ending up using this:

http://deadlytechnology.com/scripts/javascript/ajax-failure-callback/

It sends a 403 server error back if the transaction doesn't validate
which triggers my error message in the view.

On Aug 11, 2:50 am, Saliem  wrote:
> I am not quite sure what you are missing but you might want to double
> check a couple of things including:
>
> the name of your aliquot model file,
> the validate variable in your aliquot model file and
> try using the validationErrors method available for each of the models
> created and returning any errors as json
>
> please see :
>
> http://book.cakephp.org/view/410/Validating-Data-from-the-Controller
>
> On Aug 10, 3:42 pm, Tony Thomas  wrote:
>
> > This is something that's so simple, I'm embarrassed to ask. But after
> > a few dozen Google searches, I'm going to swallow my pride and post my
> > question here.
>
> > I have a simple ajax function in my controller and I want it to return
> > an error is the request is not successful. For example:
>
> > function ajax_update_box($boxId, $aliquotIds){
> >         if ($this->RequestHandler->isAjax()) { // if the request is AJAX
> >                 if($aliquots = $this->Aliquot->validateMove($aliquotIds, 
> > $boxId))
> > { // make sure a slot is open in the box
> >                         foreach($aliquots as $aliquot_id => $position ) { 
> > // validateMove
> > returns an array
> >                                 if 
> > ($this->Aliquot->save($this->data['Aliquot'] =! true)) {
> >                                         Configure::write('debug', 0);
> >                                         $this->autoRender = false;
> >                                         exit('There was an error and some 
> > of the aliquots were not
> > moved.');
> >                                 }
> >                         }
>
> >                         echo $this->unstored();
>
> >                 } else { // this is where I want it to return an error.
> >                         Configure::write('debug', 0);
> >                         $this->autoRender = false;
> >                         exit('The move did not work. Check to see if the 
> > box is full.');
>
> >                 }
> >                 Configure::write('debug', 0);
> >                         $this->autoRender = false;
> >                         exit(0);
> >         }
>
> > }
>
> > If the request doesn't pass validation in my model, I want to display
> > an error message, but I can't seem to get that to work. Everything is
> > treated as success. What am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Re: Ajax Errors

2009-08-11 Thread Saliem

I am not quite sure what you are missing but you might want to double
check a couple of things including:

the name of your aliquot model file,
the validate variable in your aliquot model file and
try using the validationErrors method available for each of the models
created and returning any errors as json

please see :

http://book.cakephp.org/view/410/Validating-Data-from-the-Controller


On Aug 10, 3:42 pm, Tony Thomas  wrote:
> This is something that's so simple, I'm embarrassed to ask. But after
> a few dozen Google searches, I'm going to swallow my pride and post my
> question here.
>
> I have a simple ajax function in my controller and I want it to return
> an error is the request is not successful. For example:
>
> function ajax_update_box($boxId, $aliquotIds){
>         if ($this->RequestHandler->isAjax()) { // if the request is AJAX
>                 if($aliquots = $this->Aliquot->validateMove($aliquotIds, 
> $boxId))
> { // make sure a slot is open in the box
>                         foreach($aliquots as $aliquot_id => $position ) { // 
> validateMove
> returns an array
>                                 if 
> ($this->Aliquot->save($this->data['Aliquot'] =! true)) {
>                                         Configure::write('debug', 0);
>                                         $this->autoRender = false;
>                                         exit('There was an error and some of 
> the aliquots were not
> moved.');
>                                 }
>                         }
>
>                         echo $this->unstored();
>
>                 } else { // this is where I want it to return an error.
>                         Configure::write('debug', 0);
>                         $this->autoRender = false;
>                         exit('The move did not work. Check to see if the box 
> is full.');
>
>                 }
>                 Configure::write('debug', 0);
>                         $this->autoRender = false;
>                         exit(0);
>         }
>
> }
>
> If the request doesn't pass validation in my model, I want to display
> an error message, but I can't seem to get that to work. Everything is
> treated as success. What am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---



Ajax Errors

2009-08-10 Thread Tony Thomas

This is something that's so simple, I'm embarrassed to ask. But after
a few dozen Google searches, I'm going to swallow my pride and post my
question here.

I have a simple ajax function in my controller and I want it to return
an error is the request is not successful. For example:

function ajax_update_box($boxId, $aliquotIds){
if ($this->RequestHandler->isAjax()) { // if the request is AJAX
if($aliquots = $this->Aliquot->validateMove($aliquotIds, 
$boxId))
{ // make sure a slot is open in the box
foreach($aliquots as $aliquot_id => $position ) { // 
validateMove
returns an array
if ($this->Aliquot->save($this->data['Aliquot'] 
=! true)) {
Configure::write('debug', 0);
$this->autoRender = false;
exit('There was an error and some of 
the aliquots were not
moved.');
}
}

echo $this->unstored();

} else { // this is where I want it to return an error.
Configure::write('debug', 0);
$this->autoRender = false;
exit('The move did not work. Check to see if the box is 
full.');

}
Configure::write('debug', 0);
$this->autoRender = false;
exit(0);
}
}

If the request doesn't pass validation in my model, I want to display
an error message, but I can't seem to get that to work. Everything is
treated as success. What am I missing?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~--~~~~--~~--~--~---