1. <small id='vrdbd'></small><noframes id='vrdbd'>

      <tfoot id='vrdbd'></tfoot>

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

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

        如何避免在 XMLHttpRequest 调用后自动重新加载页面

        时间:2023-10-13

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

          1. <tfoot id='DRoqL'></tfoot>
              • <bdo id='DRoqL'></bdo><ul id='DRoqL'></ul>

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

                <legend id='DRoqL'><style id='DRoqL'><dir id='DRoqL'><q id='DRoqL'></q></dir></style></legend>
                • 本文介绍了如何避免在 XMLHttpRequest 调用后自动重新加载页面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我知道这有点自相矛盾,因为 XMLHttpRequest 不应该重新加载页面,这就是它的全部意义所在.

                  I know this is a bit paradoxal because XMLHttpRequest shouldn't be reloading the page, and it's the whole point of it.

                  在 Chrome 最新版本、iOS 上的 Safari 和 Android 上进行了尝试.结果都一样.

                  Tried in Chrome latest version, Safari on iOS and on an Android. All same result.

                  我正在通过它发送一个带有文件的表格.效果很好,目标站点正确接收数据并显示它.发回 200,OK".(这是脸书)

                  I am sending a form through it, with files. Works great, the destination site receive correctly the data, and displays it. Sends back a 200, "OK". (It's facebook)

                  但是我的页面会自动重新加载.就像我使用 HTML 表单和提交按钮提交表单一样.(这是我原来的问题)

                  But then my page reloads automatically. Just like if I submitted the form using HTML form and a submit button. (Which was my original problem)

                  这是我的做法,来自 Javascript

                  Here is how I do it, from Javascript

                  // Get the form element
                  var formData = new FormData(document.getElementById("photosubmitform")); 
                  
                  var xhr = new XMLHttpRequest();
                  xhr.open('POST', 'https://graph.facebook.com/' + facebookWallId + '/photos', false);
                  xhr.onload = function(event)
                  {
                      var json = xhr.responseText; // Response, yay!
                  }
                  xhr.send(formData); // Sending it, will reload the page on success...
                  

                  推荐答案

                  您是否有可能通过提交表单来触发此问题?如果您不在 onsubmit 处理程序中return false,表单仍然会被提交.

                  Any chance you're triggering this by submitting a form? If you don't return false in the onsubmit handler, the form will still be submitted.

                  这篇关于如何避免在 XMLHttpRequest 调用后自动重新加载页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 Firefox 上,CORS 请求给出错误“:"(冒号) 下一篇:使用跨域 XMLHttpRequest 有哪些安全风险?

                  相关文章

                  最新文章

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

                  <tfoot id='RI3G1'></tfoot>

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

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

                      • <bdo id='RI3G1'></bdo><ul id='RI3G1'></ul>