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

  • <legend id='ZWHBt'><style id='ZWHBt'><dir id='ZWHBt'><q id='ZWHBt'></q></dir></style></legend>

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

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

      1. XHR responseText 是空字符串

        XHR responseText is empty string(XHR responseText 是空字符串)
        • <small id='o0oOZ'></small><noframes id='o0oOZ'>

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

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

                    <tbody id='o0oOZ'></tbody>
                • 本文介绍了XHR responseText 是空字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  HTML页面:

                  <!doctype html>
                  <html lang="en">
                  <head>
                      <meta charset="UTF-8">
                      <title>xhr</title>
                  </head>
                  <body>
                      <script>
                          var xhr_test = new XMLHttpRequest();
                          xhr_test.open("GET","xhrtest",true);
                          xhr_test.send();
                          alert(xhr_test.responseText);
                      </script>
                  </body>
                  </html>
                  

                  main.py 文件:

                  The main.py file:

                  import webapp2
                  from handlers import cookies,pages
                  application = webapp2.WSGIApplication([
                          ('/xhr',pages.XHR),
                          ('/xhrtest', cookies.XHRTest)
                          ],
                              debug=True)
                  

                  请求处理程序:

                  class XHRTest(webapp2.RequestHandler):
                      def get(self):
                          self.response.write('0')
                  

                  和,

                  class XHR(webapp2.RequestHandler):
                      def get(self):
                          f = open('static/html/xhr.html','r')
                          self.response.write(f.read())
                  

                  现在,当我点击 URL localhost:8080/xhrtest 时,浏览器会立即将响应 0 显示为页面内容.

                  Now, when I hit upon the url localhost:8080/xhrtest the browser promptly shows the response 0 as the page's content.

                  点击url localhost:8080/xhr间接点击/xhrtest,在alert框中弹出一个空字符串(responseText是一个空字符串)但是检查在network标签下chrome的response标签,可以看到请求的响应是0.

                  Hitting the url localhost:8080/xhr which indirectly hits /xhrtest, pops up an empty string in the alert box (the responseText is an empty string) but checking chrome's response tab under the network tab, I can see that the request's response is 0.

                  那么为什么 xhr_test.responseText 不能显示相同的响应?

                  So why is xhr_test.responseText not able to display the same response?

                  推荐答案

                  send 调用是异步的(您已将 'async' 参数设置为 true),这意味着您的警报会在请求完成之前立即发生.您应该向 xhr.onreadystatechange 添加一个事件侦听器并在其中使用响应.

                  The call to send is asynchronous (you've set the 'async' parameter to true), which means that your alert is happening immediately, before the request finishes. You should add an event-listener to xhr.onreadystatechange and use the response within that.

                  将true"更改为false"可以使这个简单的示例工作,但在一般情况下不是一个好主意.

                  Changing the 'true' to 'false' would make this simple example work, but is not a good idea in the general case.

                  Ajax 上的 MDN 页面解释了如何使用 XMLHttpRequest.

                  The MDN page on Ajax explains how XMLHttpRequest should be used.

                  这篇关于XHR responseText 是空字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
                  XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
                  Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
                  How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
                  How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
                  quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)

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

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

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

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