我必须在主模板中显示一个小模板,以便根据ajax存储库显示小模板。我已经到了在ajax请求后获取参数的阶段。
$smarty=new Smarty();
if(isset($_SERVER['HTTP_X_REQUESTED_WITH'])
&&$_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')
{
// echo "<pre>";
//print_r("Yes");
//echo "</pre>";
echo $smarty->fetch('../templates/small-page.tpl');
} else {
$smarty->display('../templates/index-page.tpl');
}在这里,echo语句不起作用,我取消了对print_r函数的注释,我可以在firebug中看到,html包含"Yes“,但它没有显示在页面上。任何帮助都是非常感谢的。
发布于 2010-12-17 06:47:00
如果smarty模板的输出是XML格式,则可以使用xmlhttp的responseXML属性,但前提是php输出正确的mime类型。
尝试:
header("content-type: text/xml");
echo $smarty->fetch('../templates/small-page.tpl');然后在客户端,
alert(xmlhttp.responseXML);告诉我它能不能用!
发布于 2010-12-17 06:05:10
我不认为Smarty和你的问题有关。Smarty会输出经过编译的模板的处理结果。
想象一下说“是”的结果。
在客户端,您有
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
//Not sure how to diplay a smarty template as a result of responseText or responseXMl
}
}responseText将保持“是”。因此,例如,尝试:
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
alert(xmlhttp.responseText);
}
}如果这样做有效,你将不得不决定你想要对文本做什么。
https://stackoverflow.com/questions/4463889
复制相似问题