• <small id='ztu7i'></small><noframes id='ztu7i'>

    <i id='ztu7i'><tr id='ztu7i'><dt id='ztu7i'><q id='ztu7i'><span id='ztu7i'><b id='ztu7i'><form id='ztu7i'><ins id='ztu7i'></ins><ul id='ztu7i'></ul><sub id='ztu7i'></sub></form><legend id='ztu7i'></legend><bdo id='ztu7i'><pre id='ztu7i'><center id='ztu7i'></center></pre></bdo></b><th id='ztu7i'></th></span></q></dt></tr></i><div id='ztu7i'><tfoot id='ztu7i'></tfoot><dl id='ztu7i'><fieldset id='ztu7i'></fieldset></dl></div>
      <bdo id='ztu7i'></bdo><ul id='ztu7i'></ul>
    <legend id='ztu7i'><style id='ztu7i'><dir id='ztu7i'><q id='ztu7i'></q></dir></style></legend><tfoot id='ztu7i'></tfoot>

        使用 Javascript 对每 15 秒一次的 ajax 调用进行速率限制和排队

        时间:2023-09-29

        <small id='YZOgU'></small><noframes id='YZOgU'>

          <legend id='YZOgU'><style id='YZOgU'><dir id='YZOgU'><q id='YZOgU'></q></dir></style></legend>

          <tfoot id='YZOgU'></tfoot>

              • <i id='YZOgU'><tr id='YZOgU'><dt id='YZOgU'><q id='YZOgU'><span id='YZOgU'><b id='YZOgU'><form id='YZOgU'><ins id='YZOgU'></ins><ul id='YZOgU'></ul><sub id='YZOgU'></sub></form><legend id='YZOgU'></legend><bdo id='YZOgU'><pre id='YZOgU'><center id='YZOgU'></center></pre></bdo></b><th id='YZOgU'></th></span></q></dt></tr></i><div id='YZOgU'><tfoot id='YZOgU'></tfoot><dl id='YZOgU'><fieldset id='YZOgU'></fieldset></dl></div>
                • <bdo id='YZOgU'></bdo><ul id='YZOgU'></ul>
                    <tbody id='YZOgU'></tbody>
                • 本文介绍了使用 Javascript 对每 15 秒一次的 ajax 调用进行速率限制和排队的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个应用程序,每次用户做某事时都会自动发推文......

                  I have an application that automatically tweets every time a user does something...

                  如果他们愿意,用户可以轻松地每秒执行一次该操作.

                  Users can easily perform that action once every second if they like.

                  Twitter 的速率限制表示它关注 15 分钟内发生了多少条推文.从技术上讲,我认为我总是低于 15 分钟,但似乎 twitter 也说嘿,你可以在 15 分钟内发布 15 个帖子,但不能在 15 秒内发布 15 个帖子"......我认为这是合理的......

                  Twitters rate limit says that it pays attention to how many tweets happen in 15 minutes. Technically I think I am always below the 15 minute mark, but it seems like twitter also says "hey you can post 15 posts in 15 minutes, but not 15 posts in 15 seconds"... which is reasonable I think...

                  我想在 javascript 端解决这个问题.我想要一个函数数组,我添加而不是实际调用 ajax,然后有一个 setTimeout 外观,检查数组开头是否有函数调用,运行该函数,删除它从阵列中取出并等待 15 秒再执行一次.

                  I would like to solve this problem on javascript side. I would like to have an array of functions, that I add to rather than actually calling the ajax, and then have a setTimeout look that checks to see if there is a function call at the beginning of the array, runs that function, removes it from the array and waits 15 seconds to do it again.

                  这将有助于随着时间的推移将推文(ajax 调用)减慢到合理的程度.

                  This will serve to slow down the tweets (ajax calls) over time to something reasonable.

                  这似乎是我应该用一个库来解决的问题,但我所看到的限制库似乎适合 忽略而不是存储中间请求.jquery 上的队列函数 似乎是用于动画并且看起来过于复杂,但可能是正确的回答...

                  This seems like something I should be solving with a library but the throttling libraries that I have seen seem to geared up to ignore rather than store intermediate requests. The queue function on jquery seems to be for animation and seems over complex, but might be the right answer...

                  想法?

                  推荐答案

                  试试这个

                  <!DOCTYPE html>
                  <html>
                  <head>
                  <meta charset="utf-8" />
                  <title>Queue things</title>
                  <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.min.js"></script>
                  <script type="text/javascript">
                  var myQueue=[],msgNum=0;
                  function queueIt(item) {
                    myQueue.push({ "item":item, "ts":new Date().getTime()});
                  }
                  function processQueue() {
                    if (myQueue.length===0) return;
                    var obj = myQueue.shift();
                    $("#content").append('<br/>'+obj.item+" "+diff(obj.ts));
                  }
                  function diff(ts) {
                      var t = new Date().getTime()-ts;
                      return t + "ms ago";
                  }
                  $(function(){
                      $("#clickMe").on("click",function() {
                          msgNum++;
                          queueIt("Message #"+msgNum);
                      });
                      setInterval(processQueue,15000);
                  });
                  
                  </script>
                  </head>
                  <body>
                  <input type="button" id="clickMe" value="Queue something"/>
                  <div id="content"></div>
                  </body>
                  </html>
                  

                  这篇关于使用 Javascript 对每 15 秒一次的 ajax 调用进行速率限制和排队的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 Typescript 中实现 Bull Queue 下一篇:jQuery stop(true, true) 跳转到队列中所有动画的末尾

                  相关文章

                  <tfoot id='Ph6q2'></tfoot>

                  1. <i id='Ph6q2'><tr id='Ph6q2'><dt id='Ph6q2'><q id='Ph6q2'><span id='Ph6q2'><b id='Ph6q2'><form id='Ph6q2'><ins id='Ph6q2'></ins><ul id='Ph6q2'></ul><sub id='Ph6q2'></sub></form><legend id='Ph6q2'></legend><bdo id='Ph6q2'><pre id='Ph6q2'><center id='Ph6q2'></center></pre></bdo></b><th id='Ph6q2'></th></span></q></dt></tr></i><div id='Ph6q2'><tfoot id='Ph6q2'></tfoot><dl id='Ph6q2'><fieldset id='Ph6q2'></fieldset></dl></div>

                      <legend id='Ph6q2'><style id='Ph6q2'><dir id='Ph6q2'><q id='Ph6q2'></q></dir></style></legend>
                        <bdo id='Ph6q2'></bdo><ul id='Ph6q2'></ul>

                      <small id='Ph6q2'></small><noframes id='Ph6q2'>