<bdo id='9W6i7'></bdo><ul id='9W6i7'></ul>
<legend id='9W6i7'><style id='9W6i7'><dir id='9W6i7'><q id='9W6i7'></q></dir></style></legend>
  • <small id='9W6i7'></small><noframes id='9W6i7'>

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

      <tfoot id='9W6i7'></tfoot>

      1. XMLHttpRequest 状态 0(responseText 为空)

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

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

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

                1. 本文介绍了XMLHttpRequest 状态 0(responseText 为空)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  无法通过 XMLHttpRequest 获取数据(状态 0 且 responseText 为空):

                  <上一页>xmlhttp=新的 XMLHttpRequest();xmlhttp.open("GET","http://www.w3schools.com/XML/cd_catalog.xml", true);xmlhttp.onreadystatechange=函数(){如果(xmlhttp.readyState==4)警报(状态" + xmlhttp.status);}xmlhttp.send();

                  它会提醒状态 0".

                  与localhost请求相同的情况(cd_catalog.xml保存为本地文件)

                  <上一页>xmlhttp.open("GET","http://localhost/cd_catalog.xml", true);

                  但是使用 localhost IP 请求

                  <上一页>xmlhttp.open("GET","http://127.0.0.1/cd_catalog.xml", true);

                  并与本地文件请求

                  <上一页>xmlhttp.open("GET","cd_catalog.xml", true);

                  一切正常(状态 200)

                  在线请求出现问题 (status=0) 的原因是什么?

                  PS:Live HTTP Headers 显示在所有 4 种情况下一切正常:

                  <上一页>HTTP/1.1 200 正常内容长度:4742

                  PS2:VMWare 上的 Apache 本地 Web 服务器(主机操作系统 Win7、来宾操作系统 Ubuntu、网络适配器 – NAT).浏览器 – 火狐.

                  解决方案

                  当你的包含脚本的 html 文件通过文件方案在浏览器中打开时,状态为 0.确保将文件放在您的服务器(apache 或 tomcat 等)中,然后在浏览器中通过 http 协议打开它.(即 http://localhost/myfile.html)这就是解决方案.

                  Cannot get data with XMLHttpRequest (status 0 and responseText is empty):

                  xmlhttp=new XMLHttpRequest();
                  xmlhttp.open("GET","http://www.w3schools.com/XML/cd_catalog.xml", true);
                  xmlhttp.onreadystatechange=function() 
                  {
                    if(xmlhttp.readyState==4)
                      alert("status " + xmlhttp.status);
                  }
                  xmlhttp.send();
                  

                  It alerts "status 0".

                  The same situation with the localhost request (cd_catalog.xml is saved as a local file)

                  xmlhttp.open("GET","http://localhost/cd_catalog.xml", true);
                  

                  But with the localhost IP request

                  xmlhttp.open("GET","http://127.0.0.1/cd_catalog.xml", true);
                  

                  and with the local file request

                  xmlhttp.open("GET","cd_catalog.xml", true);
                  

                  everything is OK (status 200)

                  What can cause the problem (status=0) with the online request?

                  PS: Live HTTP Headers shows that everything is OK in all 4 cases:

                    HTTP/1.1 200 OK
                    Content-Length: 4742
                  

                  PS2: Apache local web server on VMWare (host OS Win7, Guest OS Ubuntu, Network adapter – NAT). Browser – Firefox.

                  解决方案

                  status is 0 when your html file containing the script is opened in the browser via the file scheme. Make sure to place the files in your server (apache or tomcat whatever) and then open it via http protocol in the browser. (i.e. http://localhost/myfile.html) This is the solution.

                  这篇关于XMLHttpRequest 状态 0(responseText 为空)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:将 JSON 发送到服务器并返回 JSON,无需 JQuery 下一篇:纯 JavaScript 发送没有表单的 POST 数据

                  相关文章

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

                  <tfoot id='UMlVH'></tfoot>
                      <bdo id='UMlVH'></bdo><ul id='UMlVH'></ul>

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