Tuesday, January 21, 2014

RE: Forgive the ignorance - What is a JSON view?

Thank you,

 

That's what I needed to know.

There is no example like that in the cookbook so if they had your example that might help a lot of people with the same question.

 

Good stuff and thank you!

 

Dave Maharaj

Freelance Designer | Developer

www.movepixels.com  |  dave@movepixels.com  |  709.800.0852

 

From: cake-php@googlegroups.com [mailto:cake-php@googlegroups.com] On Behalf Of euromark
Sent: Tuesday, January 21, 2014 9:13 PM
To: cake-php@googlegroups.com
Subject: Re: Forgive the ignorance - What is a JSON view?

 

http://book.cakephp.org/2.0/en/views/json-and-xml-views.html



Am Dienstag, 21. Januar 2014 17:15:40 UTC+1 schrieb advantage+:

Reading on response and such but what is a JSON view?

 

I am building an site which is 99% based on JSON responses and that gets pushed back to the js based on the result / success / fail and the data sent from the controller to the js updates the current view accordingly.

Not using any new views or anything after submit  /view / add just the standard html views / elements so I am wondering what is a JSON view?

 

For example I try to submit a form sent via ajax:

 

In error the response from the server sent to the js from the controller is like this::

 

{

"status":false,

                    "errors":{

                                        "title":["Please enter a title."],

                                        "from":["Please enter the from who."],

                                        "description":["Please enter a description."]},

                    "clear":false,

                    "token":"$2a$10$.3FRu2riTDzyXS3vXj5.LOVW3insbLfCyjpSfCadLEIOnuwu6uh02",

                    "message":{

                                         "title":"Not quite there!",

                                        "text":"Please correct the following errors and try again."}

}

 

 

JS SNIP:

.done(function(r){

                if (r.status === true) {

                                alertMessage('success', r.message);

                                errorUpdate(handler);

                } else {

                                if(r.illegal){

                                                securityError(r);

                                }

                                alertMessage('error', r.message, r.errors);

                                setErrors(r.errors, sel)

                }             

})

 

So the js will update the form automatically (by-passing the cake error notifications , added dynamically) adding the errors where they are, reset the CSRF token and the general fail message. No view is used / rendered so just wondering if I am doing this wrong?

 

And what would a JSON view look like anyways?

 

As always thanks in advance.

 

Dave Maharaj

Freelance Designer | Developer
Description: header_logo

www.movepixels.com  |  dave@movepixels.com  |  709.800.0852

 

--
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 unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: