Hi all, i want to ask for your advice on what i am doing wrong
what i am trying to do is making an ajax call and getting any type of response from the controller. the response will be displayed in the page that initiated the ajax call but the controller never sends data back. what is weird is that the debug_kit detects the response and displays it so i get the _serialize and the result variable but not the javascript function
this is the javascript function:
<script type = "text/javascript" language = "javascript"> $(document).ready(function(){ $("button").click(function(){ $.ajax({ type : "GET", url : "<?php echo $this->Url->build(['controller' => 'users', 'action' => 'getByCategories', '_ext' => 'json']); ?>", contentType : false, processData : false, dataType : 'json', success: function(response){ console.log(JSON.parse(response)); } }); }); }); </script>
this is the action in the controller
public function getByCategories() { $id = 33; $this->autoRender = false; $cat = $this->Users->Categories->get($id); if ($this->Users->Categories->childCount($cat) > 0) { $result = $this->Users->Categories->find('all', ['conditions' => ['parent_id' => $id]]); $this->set(compact('result')); $this->set('_serialize', ['result']); } else { $result['Machines'] = $this->Users->Machines->find('all', ['conditions' => ['category_id' => $id]]); $result['Medias'] = $this->Users->Medias->find('all', ['conditions' => ['category_id' => $id]]); $this->set(compact('result')); $this->set('_serialize', ['result']); } }
if i try to access the link of this action i get null
i added the routes for the json extension
i loaded the request handler component.
the debug kit receives the response but not the javascript function
thanking you in advance