Here's how I resolved this. The save function now always returns a json array, 
so I have a result key that contains success/error. If success, I run a second 
ajax function that pulls back the element as html and updates the dom. If 
failure, I parse the 'errors' key of the json response and display them.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 31 Oct 2012, at 15:36:54, Jonathan Sundquist <[email protected]> wrote:

> 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 
> <[email protected]> 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 <[email protected]> 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
>> http://majerle.eu
>> 
>> 
>> 
>> 2012/10/31 Jeremy Burns <[email protected]>
>> 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 [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> 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 [email protected].
>> To unsubscribe from this group, send email to 
>> [email protected].
>> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
> To unsubscribe from this group, send email to 
> [email protected].
> 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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to