[英]AJAX + jQUERY: load div instantly, then refresh every X seconds
我正在使用jQUERY + AJAX每X秒刷新几个div。 我想知道在页面加载后立即(第一次)加载这些div,然后等待(例如30秒)进行每次刷新的方式。 我发现您为函数命名,然后调用刷新。 事实是,我无法弄清楚如何用我的代码来实现。
这是我的代码行:
// <![CDATA[
$(document).ready(function() {
$.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh
setInterval(function() {
//DIVs that are being loaded
$('#item01_tobeloaded').load('items/item01.php');
$('#item02_tobeloaded').load('items/item02.php');
}, 30000); // the "30000" here refers to the time to refresh the div. it is in milliseconds.
});
// ]]>
任何帮助将不胜感激:)
谢谢!
<script type="text/javascript">
$(document).ready(function() {
$("#refresh").load("refresh.php");
var refreshId = setInterval(function() {
$("#refresh").load('refresh.php?' + 1*new Date());
}, 1000);
});
</script>
这个小脚本会不断加载并刷新div“刷新”,您可以通过将1000更改为所需的值来根据需要进行调整。 1000将每秒刷新一次。
这条线
$(document).ready(function() {
$("#refresh").load("refresh.php");
准备好将内容加载到文档中,之后您可以坚持使用代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.