I make a AJAX call from my model to the controller and instead of returning just the result of the sql query it returns a whole website (with the content of the result somewhere in the middle).
Snippet code of a function inside of my model>
echo '<li> <a onclick="nodeList('.$row->id.')">'.$row->title.'</a></li>'; JFactory::getDocument()->addScriptDeclaration(" function nodeList(node_id){ alert(node_id); jQuery.ajax({ url: 'index.php?option=com_nautilus&task=update', type: 'POST', data: ({id: node_id}), success: function(data){ console.log('success'); console.log(data); }, error: function(){ console.log('error'); } }); } "); Code of my update function inside of controller.php>
public function update() { $id = $_POST['id']; $db = JFactory::getDbo(); $query = $db->getQuery(true); $db->setQuery("SELECT c.title,c.id,c.type FROM #__content c INNER JOIN #__content_parents as p ON c.id=p.node_id and p.parent_id=$id"); $result = $db->loadObjectList(); echo (json_encode($result, JSON_FORCE_OBJECT)); } Thank you!