• <tfoot id='6pFJo'></tfoot>

      1. <legend id='6pFJo'><style id='6pFJo'><dir id='6pFJo'><q id='6pFJo'></q></dir></style></legend>
          <bdo id='6pFJo'></bdo><ul id='6pFJo'></ul>

        <small id='6pFJo'></small><noframes id='6pFJo'>

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

        在 Chrome 中加载 (readyState==3) 时的 XmlHttpRequest.re

        时间:2023-10-14

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

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

                • <legend id='Sku4X'><style id='Sku4X'><dir id='Sku4X'><q id='Sku4X'></q></dir></style></legend>
                  本文介绍了在 Chrome 中加载 (readyState==3) 时的 XmlHttpRequest.responseText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试通过 ajax(通过 XmlHttpRequest (=xhr) 在 Javascript 中流式传输"(从服务器到客户端).我正在使用中描述的修改后的 handleResponse 函数HTTP Streaming"的跨浏览器实现(推)AJAX 模式

                  I am trying to "streaming" (from server to client) in Javascript by ajax (by XmlHttpRequest (=xhr). I am using modified handleResponse function described in Cross-browser implementation of "HTTP Streaming" (push) AJAX pattern

                  function handleResponse() {
                  if (http.readyState != 4 && http.readyState != 3)
                      return;
                  if (http.readyState == 3 && http.status != 200)
                      return;
                  if (http.readyState == 4 && http.status != 200) {
                      clearInterval(pollTimer);
                      inProgress = false;
                  }
                  // In konqueror http.responseText is sometimes null here...
                  if (http.responseText === null)
                      return;
                  
                  while (prevDataLength != http.responseText.length) {
                      if (http.readyState == 4  && prevDataLength == http.responseText.length)
                          break;
                      prevDataLength = http.responseText.length;
                      var response = http.responseText.substring(nextLine);
                      var lines = response.split('
                  ');
                      nextLine = nextLine + response.lastIndexOf('
                  ') + 1;
                      if (response[response.length-1] != '
                  ')
                          lines.pop();
                  
                      for (var i = 0; i < lines.length; i++) {
                          // ...
                      }
                  }
                  
                  if (http.readyState == 4 && prevDataLength == http.responseText.length)
                      clearInterval(pollTimer);
                  
                  inProgress = false;
                  }
                  

                  使用 php 脚本,它会刷新我的数据(没有 ajax,它确实会在进行时将数据刷新到浏览器)

                  With php script, which flushes me data (without ajax it really flushes data to browser while progressing)

                  我在 Firefox 中没有问题,但是 Google Chrome 和 IE 给我一个空的 responseText 而 xhr.readyState 等于 3.我在互联网上找到了该问题描述,但它没有给我任何解决方案.

                  I have no problem in Firefox, but Google Chrome and IE give me an empty responseText while xhr.readyState equals to 3. I found that problem described in the Internet, but it didn't give me any solution.

                  你知道,如何绕过Chrome中的这个实现问题吗?(w3c 说,在 readyState==3 中 responseText 不能为 NULL - Chrome 实现了这个规则,但只给出了空字符串)

                  Do you know, how to pass by this implementation problem in Chrome? (w3c says, that responseText can't be NULL in readyState==3 - Chrome implemented this rule, but gives only empty string)

                  如果您不知道,您知道某些产品中有什么可行的解决方案吗?(开源框架、库等)

                  And if you don't know, do you know any working solution in some products? (opensource frameworks, librararies etc.)

                  非常感谢您的想法.

                  解决方法是创建 iframe,将脚本调用到 iframe 并在此处刷新数据,然后通过 javascript 从 iframe 获取数据.但这不是 ajax 解决方案.我真的很想看到纯 ajax 解决方案.

                  The workaround is in creating iframe, call the script to iframe and flush data here and grab data by javascript from iframe. But this is not ajax solution. I really would like to see pure ajax solution.

                  推荐答案

                  Chrome 存在一个错误,即只有在接收到一定数量的字节后才会填充 xhr.responseText.有两种方法可以解决这个问题,

                  Chrome has a bug where it will only populate xhr.responseText after a certain number of bytes has been received. There are 2 ways to get around this,

                  设置返回的内容类型为application/octet-stream"

                  Set the content type of the return to "application/octet-stream"

                  发送一个大约 2kb 的前奏来准备处理程序.

                  Send a prelude of about 2kb to prep the handler.

                  当 readyState == 3 时,这些方法中的任何一个都应该让 chrome 填充 responseText 字段.

                  Either of these methods should make chrome populate the responseText field when readyState == 3.

                  另一方面,IE7/8 做不到,你需要借助长轮询或在 IE8 中使用 XDomainRequest 的跨域技巧,例如 MS

                  IE7/8 on the other hand can't do it, you need to resort to long polling or use the cross domain trick with XDomainRequest in IE8, a la MS

                  这篇关于在 Chrome 中加载 (readyState==3) 时的 XmlHttpRequest.responseText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何确定 XMLHttpRequest.send() 是否有效 下一篇:重用 XMLHttpRequest 对象还是创建一个新对象?

                  相关文章

                  最新文章

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

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

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

                  1. <legend id='skKV6'><style id='skKV6'><dir id='skKV6'><q id='skKV6'></q></dir></style></legend>