This question already has an answer here:
Auto Refresh DIV contents every 5 seconds code not working
                                
                                    (1个答案)
                                
                        
                2年前关闭。
            
        

我正在使用$ .get从php获取结果并更新类.actions。我想做的是每5秒钟调用一次,用最新结果更新.actions。有没有办法做到这一点的jQuery。谢谢

js

$.get('/domain/admin/requests/boxes/destroy/refreshBox.php?dstrcount=' + 'Actions', function(data) {
$(".actions").text(data);
});

最佳答案

您可以使用setInterval()

像这样

setInterval(function() {
  $.get('/domain/admin/requests/boxes/destroy/refreshBox.php?dstrcount=' + 'Actions', function(data) {
    $(".actions").text(data);
  });
}, 5000);


请参阅jsFiddle上的示例:https://jsfiddle.net/mvaw7rxr/534/

关于javascript - 每5秒钟刷新一次类(class),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49006119/

10-11 22:11
查看更多