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

  • <tfoot id='6LyPF'></tfoot>
    • <bdo id='6LyPF'></bdo><ul id='6LyPF'></ul>
  • <small id='6LyPF'></small><noframes id='6LyPF'>

  • <legend id='6LyPF'><style id='6LyPF'><dir id='6LyPF'><q id='6LyPF'></q></dir></style></legend>

        需要一个延迟函数javascript

        时间:2023-10-13
          <tbody id='ngvpC'></tbody>
          <bdo id='ngvpC'></bdo><ul id='ngvpC'></ul>

            • <tfoot id='ngvpC'></tfoot>

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

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

                  <legend id='ngvpC'><style id='ngvpC'><dir id='ngvpC'><q id='ngvpC'></q></dir></style></legend>
                  本文介绍了需要一个延迟函数javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  您好,我目前正在发出 xmhhttp 请求,但该网站需要一些时间来加载,所以我只得到 ReadyState = 3 和状态 = 200.所以我需要等到 readystate = 4 的东西,但我想限制如果readystate = 4,它每秒只检查一次,否则什么也不做.

                  Hi im currently making a xmhhttp request, but the site takes some time to load, so I only get the ReadyState = 3 and status = 200. So I need something that waits until the readystate = 4, but I want to limit this function so that it only checks once a second if the readystate = 4, else do nothing.

                  这样的延迟函数长什么样子?

                  How can such a delay function look like?

                     if (xmlhttp.readyState==4 && xmlhttp.status==200)//Add the delay here so that the else doesn't occur
                      {
                      var txt=xmlhttp.responseText;
                      .....
                    else {
                  
                      document.write("status: " + xmlhttp.readyState + " " + xmlhttp.status);
                    }
                  

                  推荐答案

                  我们可以写一个函数来检查你的 xmlhttp-object 的状态:

                  We can write a function for checking the state of your xmlhttp-object:

                  var checkState = function(xmlhttp, callback) {
                    if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                      callback(whatever, arguments, that, you, want, to, send);
                    } else {
                      // Check back again 1 sec later
                      setTimeout(checkState, 1000);
                    }
                  };
                  

                  那么你可以这样使用它:

                  Then you can use it like this:

                  checkState(xmlhttp, function(whatever, arguments, you, need) {
                    // the code here will be run when the readyState is 4 and the status is 200
                  });
                  

                  不过有两件事:

                  • 无论 readyState 是什么,checkState 函数都会返回,因此请确保您只在回调中执行依赖于它的操作,而不是之后.
                  • 如果 readyState 和 status 从来没有得到你想要的值,那么你就不走运了(但你可以扩展函数以接受第二个回调来处理超时情况).

                  这篇关于需要一个延迟函数javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用 XMLHttpRequest 的内存高效消息块处理 下一篇:XHR/使用 D3 发布请求

                  相关文章

                  最新文章

                2. <small id='mqmzh'></small><noframes id='mqmzh'>

                    <bdo id='mqmzh'></bdo><ul id='mqmzh'></ul>

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

                    <tfoot id='mqmzh'></tfoot>