jquery使用ajax实现实时刷新,轮询

来自:https://blog.csdn.net/qq_25406669/article/details/78343082

var isLoaded = false;
function reqs() {
    $.ajax({
        type: 'get',
        url: 'demo.php',
        dataType: 'json',
        beforeSend: function() {
            isLoaded = false;
        },
        success: function(res) {
            console.log(res);
        },
        complete: function() {

            isLoaded = true;
        },
        error: function() {
            console.log('请求失败~');
        }
    });
}
reqs();
setInterval(function() {
    isLoaded && reqs();
}, 3000);

 

posted @ 2019-05-08 09:32  sunseeker  阅读(3029)  评论(0编辑  收藏  举报