我想在我的控制器操作中呈现一个部分作为对 ajax 请求的响应。我的目标是在 ajax 请求成功时回显Twitter Bootstrap Alert 。
这是我的操作(redigeraLottningAction
):
if($this->getRequest()->isXmlHttpRequest()){
$this->_helper->viewRenderer->setNoRender();
$this->_helper->layout->disableLayout();
echo $this->view->partial('partial/alert-ajax.phtml', array('type' => 'success', 'msg' => 'Lyckat! Lottningen är nu sparad.'));
}
而我的部分(alert-ajax.phtml
):
<div id="alert-msg" class="alert alert-<?= $this->type?> fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<p><?= $this->msg?></p>
</div>
问题是部分中的 php 脚本作为文本输出。这是浏览器中未呈现变量时的样子:
<div id="alert-msg" class="alert alert-<?= $this->type?> fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<p><?= $this->msg?></p>
</div>
和 jquery 部分:
$(document).ready(function(){
$('#lottning-spara').click(function () {
$.ajax({
type: "POST",
url: '/turnering/redigera-lottning',
cache: false,
data: {id: getParam("turnering"), klass_id: getParam("klass"), type: "spara", lottning: $('#lottning_str').val()},
dataType: 'html',
success: function(msg){
$('#alert-div').html(msg);
},
error: function(){
$('#alert-div').html('Error!');
}
});
});
});
任何想法为什么不呈现部分的php?
编辑是粗体的。
问题解决了。alert-ajax.phtml 文件是不同的字符集类型。