Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to prevent Controller from sending view

I'm communicating with my controller via AJAX and requesting an action. But depending to the result on the said controller, I want it to return particular values, but by now it return a whole "index" template.

I just want it to return what I say it to return. How can I do that?

Example:

// In some view...
$.post('my/action', send, function(res){
    // 'res' variable should be 'true' or 'false', not the whole View html, etc...
});


18.5k
Accepted
answer
edited Sep '14
$this->view->disable();
$response = new Phalcon\Http\Response(),

// Do things here.
$varWithThingsDone = 'Doing things.';

$response->setJsonContent(array(
    'response' => $varWithThingsDone
));

You might want to know that you can also check if the post is from AJAX:

$this->request->isAjax();

@RompePC perfect, worked like a charm, thanks.