Zend重定向到json响应

时间:2015-04-06 10:35:46

标签: json zend-framework

我正在使用ajax向Zend Controller发出POST请求。

$.ajax({
            type: 'POST',
            data: data,
            dataType: "json",
            error: function(e){
                console.log(e);
            }
            success: function(msg){
                if(msg.success){
                   //doesn't reach here. I'm getting redirected
                    console.log('success');
                }
            }
        });

在zend中,我有以下几行:

$this->jsonResponse(array('success' => true, 'embed' => 'some text here'));

我的问题是我被重定向到包含响应的json响应页面(即实际页面)。回答是正确的,但我不想被重定向。我不知道发生了什么,为什么会这样。

1 个答案:

答案 0 :(得分:0)

在控制器中编写这些代码

$this->_helper->layout()->disableLayout(); //to disable layout
$this->view->jsonResponse = json_encode(array(
'success' => true,
'embed' => 'some text here'
)); // encode array

并在视图中写下这一行

echo $this->jsonResponse;
相关问题