当我单击一个链接时,我正在从数据库中写入我的 $_SESSION 变量。
public function getProjectById($id){
$query="SELECT * FROM projects WHERE id=\"$id\"";
$result=mysql_query($query);
$num=mysql_numrows($result);
while ($row = mysql_fetch_object($result)) {
$_SESSION['projectid'] = $row->id;
$_SESSION['projecttitle'] = $row->title;
$_SESSION['projectinfo'] = $row->info;
$_SESSION['projecttext'] = $row->text;
$_SESSION['projectcategory'] = $row->category;
}
}
现在我的变量被覆盖了,我想在我的 index.php 中显示这些变量,如下所示:
<div id="textContent">
<?php
if(isset($_SESSION['projecttext']) && !empty($_SESSION['projecttext'])) {
echo $_SESSION['projecttext'];
}else {
echo 'No text';
}
?></div>
但是当然,我的页面不会自动刷新。我怎样才能做到这一点?
编辑:调用代码:
$(document).on("click", ".sublink", function(){
var subsite = $(this).data('subsite');
var category = $(this).data('category');
var title = $(this).data('title');
var info = category + "/" + title;
var lower = info.toLowerCase();
var nospaces = lower.split(' ').join('');
$('#imageContent').load('php/getImages.php?info='+nospaces);
$('#textContent').load('php/getProjectById.php?id='+subsite);
});