Well then you need to return a JSON object, and set the HTML to be the
content of the JSON object.

On Dec 6, 3:17 pm, "Dave" <[email protected]> wrote:
> I need to keep the if statement. Problem is , will try to explain so it
> makes sense.
>
> I have 2 <div> one for the current user data displayed, click edit and that
> <div id="user_content"> toggles away and the <div is="user_form"> toggles in
> giving a sliding overlapping effect. The user clicks save and the <div
> is="user_form"> toggles out hiding the form and the  <div id="user_content">
> toggles back in showing the updated content. But if the user attempts to
> save the data that’s not valid I do not want the toggling of anything to
> happen so I wanted the "if success then do this" if not just return the form
> with the errors for correcting. Is there an easy way to set this up?
> (without client side validation)
>
> Thanks,
>
> Dave
>
> -----Original Message-----
> From: Miles J [mailto:[email protected]]
> Sent: December-06-09 6:48 PM
> To: CakePHP
> Subject: Re: Help With Ajax response - Ajax Handler component
>
> Well response.success will never work because your not passing a JSON
> object. Just remove the if statement in the JS.
>
> When your responding as html, no object is sent back, just the html itself.
>
> On Dec 6, 1:31 pm, "Dave" <[email protected]> wrote:
> > I am trying to edit a form using Ajax. I have the submit, save or
> > error all working. Just the response I am having problems with. I am
> > trying to use Miles Ajax Handler component and basically from the
> controller i need to :
>
> > if form saves return a success response and the Ajax view with the
> > updated content. If it does not save return a fail response and show
> > the errors on the form. I know i could use Ajax to validate but that's
> > more of a headache and for what i need it for i really don't care
> > about user side validation, the form coming back showing errors will work
> just fine.
>
> > I Need the fail or success response to pass to the JavaScript because
> > fail and success  will have 2 different functions so i need to know
> > what comes back and how the site should respond accordingly.
>
> > script:
> > $(this).ajaxSubmit({
> >   type:    'post',
> >   url:      form_url,
> >   data:      queryString,
> >   success: function () {
>
> >    // Response was a success
> >    if (response.success == true)
> >    {
> >     //do my stuff here for success
>
> >    // Response contains errors
> >    } else {
>
> >     do my stuff here for fail
> >    }
> >   }
> >  });
>
> > Controller snip of the save part:
> > if (!empty($this->data)) {
> >                   $this->Experience->id = $id;
> >                   if ($this->Experience->save($this->data, true)) {
> >                       $this->set('experience',
> > $this->Experience->getExperienceInfo($experience['Experience']['id'],
> > $this->Auth->user('id')));
> >                                   $this->layout = 'ajax';
>
> > $this->render('/elements/experiences/ajax_edited_block');
> >                                   $this->AjaxHandler->response(true);
> >                                   $this->AjaxHandler->respond('html');
>
> >                   } else {
> >                                   $this->AjaxHandler->response(false);
> >                                   $this->AjaxHandler->respond('html');
> >                   }
> >               }
>
> > Do anyone have any ideas how I can return success = true and the html
> > response or success is false and return the form with the errors so
> > that the javascript can carry on?
>
> > Thaks
>
> > Dave
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others
> with their CakePHP related questions.
>
> You received this message because you are subscribed to the Google Groups
> "CakePHP" group.
> To post to this group, send email to [email protected] To
> unsubscribe from this group, send email to
> [email protected] For more options, visit this group
> cake-php+athttp://groups.google.com/group/cake-php?hl=en
> No virus found in this incoming message.
> Checked by AVG -www.avg.com
> Version: 9.0.709 / Virus Database: 270.14.94/2545 - Release Date: 12/06/09
> 16:07:00

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to