2012-11-02 32 views
1

我想要CakePHP的JSON響應,我將使用backbone.js進行渲染。但是,而不是JSON響應我得到default.ctp內容還與JSON響應我不知道爲什麼。有沒有什麼我可以不包括在JSON響應default.ctp內容?Backbone與CakePHP JSON響應

這裏是我的代碼,其中數據 - >輸出包含取出的行獲取JSON

<?php 
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
header('Cache-Control: no-store, no-cache, max-age=0, must-revalidate'); 
header('Cache-Control: post-check=0, pre-check=0', false); 

//header('Content-type: text/json'); 
header('Content-type: application/json'); 
header('Pragma: no-cache'); 
//header("X-JSON: ".$content_for_layout); 

$response['status'] = $status; 
//$response['data']['titleForLayout'] = $title_for_layout; 

$response['data']['validationErrors'] = $this->validationErrors; 

$response['data']['sessionFlash'] = $this->Session->read('Message.flash.message'); 

//$response['data']['data'] = $this->data; 
$response['data'][$this->request->params['controller']]['output'] = isset($output)?$output:null; 

$output = json_encode($response); 

if (isset($this->params['url']['callback'])) { 
    echo $this->params['url']['callback'] . '(' . $output . ');'; 
} else { 
    echo $output; 
} 

?>

請幫我一把。

我得到JSON響應,但問題是得到default.ctp內容圍繞我不想要的響應。有沒有辦法做到這一點?

回答

0

您需要設置的佈局是AJAX或空佈局。

在設置控制器此:

$this->layout = 'ajax';