[英]How can I display ajax results in a view in CakePHP without including the default template in the ajax response?
我正在使用CakePHP中的AJAX進行一些實驗,它似乎工作,除了返回的視圖包含默認模板。 我怎樣才能擺脫它(甚至只為視圖指定一個不同的空模板)?
function ajaxFunction() {
//do stuff
$this->layout= 'ajax';
}
Ajax是一個包含的空白布局,以防止添加額外的標記,正是您想要的。
嘗試使用RequestHandler組件。 這將自動為您處理。 然后,您可以在AppController :: beforeFilter()中執行類似的操作
if($this->RequestHandler->isAjax()) {
Configure::write('debug',0);
}
您還需要關閉調試輸出,否則蛋糕會噴出您通常在頁面底部看到的所有調試信息:
function ajaxFunction() {
//do stuff
Configure::write('debug', 0);
$this->layout= 'ajax';
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.