【发布时间】:2021-04-19 03:17:11
【问题描述】:
我正在尝试处理每隔几秒重新加载 PHP 脚本的 AJAX 自动重新加载脚本
这是脚本:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.js"></script>
<script>
$(document).ready(function() {
function reload() {
$('#autoload').load('assets/php/get-emails.php');
}
setInterval(reload, 1000);
});
</script>
HTML表格代码(第):
<table class="table" style="background-color :1c1f20;" id="inbox autoload">
<thead>
<tr style="color: grey;text-align:center;font-weight:bolder;">
<the scope="col"> From </th>
<the scope="col">Title</th>
<the scope="col">details</th>
<the scope="col">forward</th>
</tr>
</thead>
<tbody>
<div>
<?PHP
DisplayEmails($_COOKIE['t_email_address_1']);
?>
</div>
</tbody>
</table>
但它不起作用,我尝试了我找到的所有解决方案。
顺便说一句:get-emails 打印出来......为一张桌子打标签。
而自动加载id在table标签中。
提前致谢!
【问题讨论】:
-
请定义“不起作用”。页面上会发生什么?您在浏览器的开发工具网络选项卡中看到了什么?你看到任何错误吗?请求返回什么?同时分享您表格的 HTML,以便我们更好地帮助您
-
您不能将
<div>作为<tbody>的孩子,只有<tr> -
id="inbox autoload"? -
嘿,页面上没有任何反应。开发工具网络选项卡在给定时间后不会请求任何内容。我想用新的电子邮件(tr 标签)更新表格。但是开发工具在控制台中没有错误...
-
好的,它不会加载,因为没有 id 为
autoload的元素,正如@LawrenceCherone 所指出的那样。 jQuery 找不到它,所以它不会费心提出请求。它必须是id="autoload",而不是id="inbox autoload"
标签: javascript php html jquery ajax