Ajax Heartbeat using setInterval, Preventing multiple calls at the same time

后端 未结 3 1398
不知归路
不知归路 2021-01-01 00:06

I wish to make an AJAX call using jQuery as a \"heartbeat\" in the background so that my web application can check for new data. For example every 10 seconds.

I hav

3条回答
  •  长发绾君心
    2021-01-01 00:51

    try setting another timeout from your ajax success function:

    function poll() {
        setTimeout( function() {
            $.ajax(.......).success( function(data) {
                poll();  //call your function again after successfully calling the first time.
            });
        }, 10000);
    }
    

提交回复
热议问题