Never create a new response object
there is already one available in your controller

just use 

    $this->response->body($content);

as documented


Am Freitag, 16. August 2013 19:16:32 UTC+2 schrieb cesar calvo:
>
> I use this in my AppController
>
> public function jsonResponse($array) {
>         return new CakeResponse(array('body' => json_encode($array)));
>     }
>
> Then on a controller call jsonResponse
>
>
> Note: if you are usin Security component on beforeFilter:
>
> if ($this->request->is('ajax')) $this->Security->unlockedActions = 
> array($this->request->action);
>
> On Thursday, August 15, 2013 11:03:34 PM UTC-3, Renato Bigliazzi wrote:
>>
>> Hi , I can not do the twitter bootstrap component typeahead work with 
>> cake. i use https://github.com/rudylee/cbunny , but dont work form me.
>>
>>
>> In my view
>>
>> JS
>>
>> <script type="text/javascript">
>>  $(document).ready(function(){ 
>> $('#itemdesc').typeahead({
>>     source: function (query, process) {
>>       return $.ajax({
>>         url:'<?php echo 
>> Router::url(array('controller'=>'Invoices','action'=>'localizaprodutos'));?>',
>>         type: 'get',
>>         data: {q: query},
>>         dataType: 'json',
>>         success: function (json) {
>>           return process(json);
>>         }
>>       });
>>     }
>>   });
>> });
>> </script>
>>
>> HTML
>> <input type="text" name="itemdesc[]"  class="input-large" id="itemdesc" 
>> data-provide="typeahead"/>
>>
>>
>> and controller
>>
>> public function localizaprodutos(){
>>  $this->autoRender = false;
>>         $this->RequestHandler->respondAs('json');
>>
>>         // get the search term from URL
>>         $term = $this->request->query['q'];
>>         $users = 
>> $this->Invoice->Invoicedetail->Inventoryitem->find('all',array(
>>             'conditions' => array(
>>                 'Inventoryitem.desc LIKE' => '%'.$term.'%'
>>             )
>>         ));
>>
>>         // Format the result for select2
>>         $result = array();
>>         foreach($produtos as $key => $produto) {
>>             array_push($result, $produto['Inventoryitem']['desc']);
>>         }
>>         $produtos = $result;
>>         
>>         echo json_encode($produtos);
>>     }
>>
>>
>> Thanks
>>
>> Renato
>>
>>
>>
>>
>>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to