Friday, March 18, 2011

Re: CakePHP, jQuery & JSON

That works very well... Thank you guys !

On 18 Mrz., 12:28, LipeDjow <liped...@gmail.com> wrote:
> Yes.
>
> Instead returning the value in action, you can set it to view and load a
> general element for JSON.
> Like this (using Taffarel's example):
>
> function json(){
>     //bring some data in database
>      $json = $this->Test->find('all');
>      $this->set('json', $json);
>      $this->render('../elements/json.ctp');
>
> }
>
> // views/elements/json.ctp
> <?php echo json_encode($json); ?>
>
> then in my view I use the method getJson
>
> $.getJSON('<?php echo $this->Html->url(array('controller'=>'tests',
> 'action'=>'json'))?>', function(data){
>       $("div").append(data);
>
> });
>
> I think this will not break MVC.
>
> HTH
> LipeDjow

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate