2011-11-24 75 views
0

我在我的smarty模板中有一个div,我想通过ajax调用一个PHP文件来获取/显示另一个模板文件。这将包含网站上的一个页面列表,这些页面将被排序,您可以点击向上/向下箭头对它们进行重新排序,因此我需要它在每次点击后重新加载相同的模板。在另一个模板中使用ajax调用/重新加载smarty模板

这可能吗?

<div id="pagelist_container"></div> 
<script type="text/javascript"> 
    {literal} 
    $(document).ready(function(){ 
     $("#pagelist_container").load("path_to_file/pages.php"); 
    }); 
    {/literal} 
</script> 

然后pages.php是:

$smarty->display('ajax/pages.tpl'); 

每当我把智者行我得到一个500错误。

+0

你能写出错误吗? – VMAtm

回答

0

必须在您的ajax响应文件中创建一个新的smarty对象,请注意您必须在此文件中包含Smarty.class.php。这是path_to_file/pages.php的内容:

// include smarty (assuming you have smarty in your path) 
require_once('Smarty.class.php'); 
// initialize smarty 
$smarty = new Smarty(); 
// setup cache, template_c & templates directory 
$smarty->templates_c = "templates_c"; 
// assign any variables to smarty here 
$smarty->assign('<variable>', $variable); 
// fetch output for your pages 
$output = $smarty->fetch('ajax/pages.tpl'); 
// return the content of the template to ajax caller 
echo $output;