• <tfoot id='X56T9'></tfoot>
      <bdo id='X56T9'></bdo><ul id='X56T9'></ul>

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

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

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

        当任何 XMLHttpRequest 完成时如何运行函数?

        时间:2023-10-13
        <legend id='mZtki'><style id='mZtki'><dir id='mZtki'><q id='mZtki'></q></dir></style></legend>
      1. <i id='mZtki'><tr id='mZtki'><dt id='mZtki'><q id='mZtki'><span id='mZtki'><b id='mZtki'><form id='mZtki'><ins id='mZtki'></ins><ul id='mZtki'></ul><sub id='mZtki'></sub></form><legend id='mZtki'></legend><bdo id='mZtki'><pre id='mZtki'><center id='mZtki'></center></pre></bdo></b><th id='mZtki'></th></span></q></dt></tr></i><div id='mZtki'><tfoot id='mZtki'></tfoot><dl id='mZtki'><fieldset id='mZtki'></fieldset></dl></div>
            <tbody id='mZtki'></tbody>

              <tfoot id='mZtki'></tfoot>

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

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

                • 本文介绍了当任何 XMLHttpRequest 完成时如何运行函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在处理一个项目,该项目有几个我无法更改的脚本.这些脚本通过 AJAX 更新页面.更新完成后,我需要运行一些代码.

                  I'm working on a project that has several scripts that I cannot change. These scripts update the page via AJAX. When the update is complete I need to run some code.

                  当任何 XMLHttpRequest 完成时是否会触发任何事件?(或任何 XMLHttpRequest 状态更改?).

                  Is there any event that fires when any XMLHttpRequest is complete? (or any XMLHttpRequest state change?).

                  不幸的是,我无法访问用于发出请求的特定 XMLHttpRequest 对象.

                  Unfortunately I cannot access the specific XMLHttpRequest object used to make the request.

                  谢谢,

                  推荐答案

                  不使用 jQuery,您可以挂钩 open 方法来为每个 XHR 对象的 readystatechange 事件附加一个监听器在 XHR 对象被 opened 时.确保在发生任何 Ajax 之前运行以下代码:

                  Without jQuery, you can hook the open method to attach a listener for each XHR object's readystatechange events at the time the XHR object is opened. Ensure the following code runs before any Ajax occurs:

                  // save the real open
                  var oldOpen = XMLHttpRequest.prototype.open;
                  
                  function onStateChange(event) {
                      // fires on every readystatechange ever
                      // use `this` to determine which XHR object fired the change event
                  }
                  
                  XMLHttpRequest.prototype.open = function() {
                      // when an XHR object is opened, add a listener for its readystatechange events
                      this.addEventListener("readystatechange", onStateChange)
                  
                      // run the real `open`
                      oldOpen.apply(this, arguments);
                  }
                  

                  或者,如果您只关心成功的 load 事件,则可以侦听该事件而不是 readystatechange.

                  Alternatively, if you only care about successful load events, you can listener for that event instead of readystatechange.

                  这篇关于当任何 XMLHttpRequest 完成时如何运行函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:承诺,如何将变量传递给 .then 函数 下一篇:查看正在进行的 AJAX 调用的简单方法是什么?

                  相关文章

                  最新文章

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

                    1. <legend id='a7lhE'><style id='a7lhE'><dir id='a7lhE'><q id='a7lhE'></q></dir></style></legend>
                    2. <small id='a7lhE'></small><noframes id='a7lhE'>

                      <tfoot id='a7lhE'></tfoot>