weixin_33724059 2017-02-28 18:17 采纳率: 0%
浏览 25

jQuery间隔不起作用

I've made a small script to load a page into a div of another page, which gets refreshed every 5 seconds.

The page is loaded as expected, but the interval doesn't seem to work.

I already searched for a solution, but all threads are saying that my code should work like that. So I decided to post the full code here.

JQuery (and AJAX):

<script>
function load(){
    $('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () {
         $(this).unwrap();
    });
}

load(); // run it on pageload
setInterval(function(){
    load() // this should run every 5 seconds
}, 5000);
</script>

The chatlogframe.php file contains a SQL Select query. The data should be reloaded every time the scipt gets executed.

UPDATE:

I checked the Chrome Console where it says Uncaught TypeError: $(...).unwrap is not a function

I don't think that the function is wrong, but maybe it helps.

UPDATE 2:

Heres the html div:

<div id='chatload'></div>
  • 写回答

1条回答 默认 最新

  • weixin_33696822 2017-02-28 18:19
    关注

    It works. May be there's some issue with your code in $('#chatload').load('/intern/chat/chatlogframe.php/?name=muster',function () { $(this).unwrap(); });

    .unwrap() could be possible issue but to isolate that you would need to post your sample HTML container.

    function load() {
      console.log("Do something");
      $('#chatload').load('https://jsonplaceholder.typicode.com/posts/1', function() {
        $(this).unwrap();
      });
    }
    
    load(); // run it on pageload
    setInterval(function() {
      load() // this should run every 5 seconds
    }, 5000);
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    
    <div id="chatload"></div>

    </div>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘