在没有布局的情况下从控制器接收回声答案

I have something like this:

$.ajax({
    type: "POST",
    url: "index/test",
    data: { from: from, to: to }
}).done(function(res) {
    alert(res);
});

and the answer from the controller is:

public function testAction()
{
    echo 555;
}

But the problem is that, this returns the layout with the answer echo 555;

How can I deny to render the layout and only leave the echo answer?

You can disable the layout by adding this line of code in your controller action method

$this->_helper->layout->disableLayout();

 public function testAction()
 {
     $this->_helper->layout->disableLayout();
     echo 555;
 }

In actions that you don't want to render any view or layout use these lines of code as appropriate:-

//To disable view rendering
$this->_helper->viewRenderer->setNoRender(true);
//To disable layout
$this->_helper->layout->disableLayout();

For example:-

public function testAction()
{
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender(true);
    echo 555;
}

You might wan't to take a look at contex switching too, in particular the ajaxContext. This is a more 'ZF' way of doing it and will automatically disable layout and set the correct headers.