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>';

    function nodeList(node_id){

            url: 'index.php?option=com_nautilus&task=update',
            type: 'POST',
            data: ({id: node_id}),
            success: function(data){
                error: function(){

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!

2 Answers 2


You have to specify the output format. Otherwise, Joomla assumes Html.

For instance, working with FoF framework, you define in the Url &format=json to get a JSON rendered view.

FoF - Automatic views and web services


If you still want to call your ajax function placed inside the controller, without any output format then place code to exit your controller method before the ending curl bracket so that the view won't be called using the exit(); code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.