Wednesday, October 31, 2012

Re: JQuery save success/error

Is your goal to output some message if they have successfully filled out your form and possibly add a little extra data to the success message?  If so just hide the success message by default, add some selectors that you can populate with the json that's returned on success, and then show the message.

As far as the failure is concerned again have hidden elements on the form that you can select and add the validation messages to.  Or there are also plenty of jQuery validation plugins out there that you could do your validation on the fly using onBlur or onFocus for that matter.


On Wed, Oct 31, 2012 at 10:33 AM, Jeremy Burns | Class Outfit <jeremyburns@classoutfit.com> wrote:
Completely - but how do I render the element as json? As soon as I do $this->render('/elements/whatever'); it's returned as straightforward html.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 31 Oct 2012, at 15:28:01, Tilen Majerle <tilen.majerle@gmail.com> wrote:

in both cases return json value and have keys eg. "success" (true/false) and "data". If "success" == true, just "print" data, if "success" == false, than use data as json, and decode that string and print validation errors, or generate string in controller for errors and print it..understand ?
--
Lep pozdrav, Tilen Majerle



2012/10/31 Jeremy Burns <jeremyburns@classoutfit.com>
Not an expert at jQuery, but getting there.

I'm submitting data to a controller function that saves a record via ajax. If the save works, I'm rendering an element, which then appears back in the ajax form as html ready to be placed into a dom element. All good - that works fine. But if the save fails I want to return an array that includes the validation errors - that really ought to be json. So on success I want html, on error I want json - and I can't have both.

How do I either (i) render the element but have it returned as json (and ideally tack in a 'success' key that I can check in the jQuery) or (ii) otherwise determine the success/error state when html has been returned to the jQuery?

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 


--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: