所以这里是问题,我有一个index.php
(与所有的PHP代码),我有一个index.tpl
文件与所有的HTML的东西。但现在因为我使用ajax,我有另一个PHP文件,应该输出一些数据(data.php)。问题是我不知道如何选择data.php文件中的模板,我所知道的只是index.php
我有一个显示tpl ($Smarty->display($filename);
的函数),但我不想再次显示模板,在data.php
文件我只想分配一些变量需要显示在index.tpl
smarty模板
编辑:
确定这将是很长: 首先我需要解释我想实现的目标。我有index.php和data.php。在index.php:
<?php
include("../include/config.php");
include("../include/functions/import.php");
$thebaseurl = $config['baseurl'];
$query ="SELECT name FROM contacts";
$results = $conn->execute($query);
$select-names = $results->getrows();
STemplate::assign('select-names',$select-names);
$templateselect = "index.tpl";
STemplate::display($templateselect);
?>
的index.tpl里是有点长,所以我会发布重要组成部分:
xmlhttp.open("get","data.php?q="+str,true);
这是AJAX代码,该代码发送+ STR值GET方法data.php文件然后使用该值并从数据库中提取一些数据。
data.php:
$q=$_GET["q"];
$sql="SELECT * FROM contacts WHERE name = '$q'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$name = $row['name'];
}
STemplate::assign('name',$name);
$templateselect = "index.tpl";
STemplate::display($templateselect); //the second display
?>
我使用该类这里STemplate的Smarty的功能,但你得到的是代码。
我希望你明白现在有什么问题。如何在不显示模板文件的情况下将变量分配给模板。这样,$ name变量可以在index.tpl中找到(名称显示在数据库中),但由于data.php中的显示函数,整个内容会再次显示。
要么我误会提出这个问题或者你问的问题是不可能的。你想让ajax调用data.php刷新显示的页面?内容如何显示两次?请显示您的JavaScript代码。 – Alfwed