【发布时间】:2017-02-07 20:16:19
【问题描述】:
我正在尝试不时刷新页面上的一些元素。我知道这里有一百万个关于这个的话题,我试图让我的工作,但这是我需要更新的内容..
这是页面加载时生成的代码:
<div id="galleria">
<?php
$a = array();
$dir = '../public/wp-content/uploads/2012/01';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (preg_match("/\.png$/", $file)) $a[] = $file;
elseif (preg_match("/\.jpg$/", $file)) $a[] = $file;
elseif (preg_match("/\.jpeg$/", $file)) $a[] = $file;
}
closedir($handle);
}
$totalImgs = count($a);
$imgUsed = array();
for ($j = 0; $j < 100; $j++)
{
do
{
$randIndex = mt_rand(0, $totalImgs);
}
while ($imgUsed[$randIndex] === TRUE);
$imgUsed[$randIndex] = TRUE;
echo "<img src='" . $dir . '/' . $a[$randIndex] . "' />";
}
?>
</div>
我想每 10 秒自动刷新一次,但不重新加载页面。我已经阅读了 ajax,似乎这是可能的,但我似乎无法让它工作。
所做的只是显示 Galleria div,并在 div 中加载 100 张图像。然后 Galleria 脚本接管并很好地显示它。 AJAX 或 JQuery 会更好吗?
感谢您的帮助!
【问题讨论】:
标签: ajax jquery partial-page-refresh