Javascript 自动刷新div内容,由jquery include ajax调用加载
我正在使用jQuery include ajax调用从Javascript 自动刷新div内容,由jquery include ajax调用加载,javascript,jquery,html,ajax,Javascript,Jquery,Html,Ajax,我正在使用jQuery include ajax调用从now\u playing.php(shoutcast now playing content)加载输出,效果很好 我的代码: <script> $(function(){ $("#now_playing").load("now_playing.php"); }); </script> <div id="now_playing"></div> $(函数(){ $(“#now_pla
now\u playing.php
(shoutcast now playing content)加载输出,效果很好
我的代码:
<script>
$(function(){
$("#now_playing").load("now_playing.php");
});
</script>
<div id="now_playing"></div>
$(函数(){
$(“#now_playing”).load(“now_playing.php”);
});
我只需要每隔5秒左右更新一次div输出内容。
我可以为脚本或div部分添加哪些代码?
谢谢大家! 您可以这样做:
将load()
放入函数中,然后使用setInterval
每隔5秒调用一次
function loadNowPlaying(){
$("#now_playing").load("now_playing.php");
}
setInterval(function(){loadNowPlaying()}, 5000);
您可以使用
setInterval
。像
setInterval(function(){
$("#now_playing").load("now_playing.php");
...
}, 5000);
它将执行加载
now\u playing.php
,并每隔5秒(5000毫秒)执行您想要的其他操作尝试使用setInterval()执行:
了解了Magicprog.fr、augustoccesar和Edan Feiles的建议,并认为Magicprog.fr的解决方案是最好的,因为它首先加载now_playing.php输出,然后在给定的时间间隔内进行更新:
<script>
function loadNowPlaying(){
$("#now_playing").load("now_playing.php");
}
setInterval(function(){loadNowPlaying()}, 5000);
</script>
函数loadNowPlaying(){
$(“#now_playing”).load(“now_playing.php”);
}
setInterval(函数(){loadNowPlaying()},5000);
非常感谢您的帮助:)请更正邮件中的代码,有些代码缺失
<script>
function loadNowPlaying(){
$("#now_playing").load("now_playing.php");
}
setInterval(function(){loadNowPlaying()}, 5000);
</script>