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