如何在特定时间段内调用Ajax请求? [英] How can I call an Ajax Request in a specific time Period?

查看:74
本文介绍了如何在特定时间段内调用Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

**我有一个棘手的问题,就是我想每小时拨打一次ajax电话。我不想在那个小时内发出第6个请求。但是一小时之后,我再次制作了五个ajax再打电话一小时。我正在使用jquery我写的一些代码如下。有什么帮助吗? **

**I am having a tricky question that is I want to make a ajax call only 5 times per hour.I don't want to make 6th request within that hour.But after one hour exactly, I again make five ajax call with again one hour.I am using jquery some code I wrote like below.Any help? **

function getBubbles(){
    $.ajax({
        type : 'POST',
        url  : '/PostData',
        data : data,
        success : function(response){
            console.log(response);
        }
    });
}


推荐答案

使用setTimeOut();

Use setTimeOut();

$.ajax({
    url: "test.html",
    error: function(){
        // will fire when timeout is reached
    },
    success: function(){
        //do something
    },
    timeout: 12000// sets timeout to 12 seconds
});

这篇关于如何在特定时间段内调用Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆