有一个页面显示"表"缩略图代表数据。现在,我有一个页面每10秒左右刷新一次,以显示最新数据。我注意到页面刷新速度很慢,页面框架没有完全加载的时间很长。我做了一些研究,并确定AJAX可能是显示数据的最佳方式,因此页面不必刷新。我的问题是 - 如何使用Ajax正确更新页面上的数据?非常感谢任何帮助。我是Ajax的新手。
这是我的代码:
<?php
session_start();
if(isset($_SESSION['username']))
{
}
else
{
$_SESSION['error']="You are logged in.";
header('Location: index.php');
exit;
}
?><!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=0"/> <!--320-->
<meta http-equiv="refresh" content="5; URL=display.php">
<head><link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Michroma" />
<link rel="stylesheet" href="carpooldisplay.css">
<script src="http://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="/js/script.js"></script>
<style>
img.logo{
float:right
width: 175px;
height: 175px;
}
<!--
.flashgroup{
border:3px solid green;
}
-->
</style>
</head>
<body>
<br><br>
<div id="display"><legend class="DISPLAY"></legend>
<?php
include "../../includes/databaseconnections/demo/database_connection.php";
///////////////////////////////////////////////////////////////////////////////////////////////
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
else{
$query = "SELECT * FROM Table1 LEFT JOIN Table2 USING (Table2.ID) WHERE Table1.status = '0' ORDER BY dateSelected ASC LIMIT 25";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
if ($row[leftGym] == "1") { $flash = "flash";} else {$flash ="";}
if ($row['photoLink'] == NULL)
{
$row['photoLink'] = "endofgroup";
}
echo "<a href='leftgym.php?sid=${row['ID']}'><div class='container'><center><figure><img id='{$row["ID"]}' src='images/{$row["photoLink"]}.jpg' draggable='true' ondragstart='dragStart(event)' width='150' height='150' class='$flash' >" . "<figcaption><center><font size='6'>" .$row['firstName'] ."<br>". $row['lastName'] . "</figcaption></figure></div></center>";
}
/* free result set */
mysqli_free_result($result);
}
}
mysqli_close($link);
/////////////////////////////////////////////////////////////////////////////////
?>
</div>
</div>
</div>
-->
</div>
</body>
</html>