I'd like to render a partial as a response to an ajax request in my controller action. My goal is to echo a Twitter Bootstrap Alert when ajax request is successful.
Here is my action (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.'));
}
And my partial (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>
The problem is that the php scripts in the partial is outputed as text. This is what it looks like in the browser with variables not rendered:
<div id="alert-msg" class="alert alert-<?= $this->type?> fade in">
<a class="close" data-dismiss="alert" href="#">×</a>
<p><?= $this->msg?></p>
</div>
And the jquery part:
$(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!');
}
});
});
});
Any ideas why the php in partial is not rendered??
Edits are bold.
Problem Solved. The alert-ajax.phtml file was a different charset type.
Problem Solved. The alert-ajax.phtml
file was a different charset type.