久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

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

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

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

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

        如何在 IE 中從 Javascript 訪問 XHR responseBody(用于二

        how do I access XHR responseBody (for binary data) from Javascript in IE?(如何在 IE 中從 Javascript 訪問 XHR responseBody(用于二進(jìn)制數(shù)據(jù))?)
          <i id='O2cbi'><tr id='O2cbi'><dt id='O2cbi'><q id='O2cbi'><span id='O2cbi'><b id='O2cbi'><form id='O2cbi'><ins id='O2cbi'></ins><ul id='O2cbi'></ul><sub id='O2cbi'></sub></form><legend id='O2cbi'></legend><bdo id='O2cbi'><pre id='O2cbi'><center id='O2cbi'></center></pre></bdo></b><th id='O2cbi'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='O2cbi'><tfoot id='O2cbi'></tfoot><dl id='O2cbi'><fieldset id='O2cbi'></fieldset></dl></div>

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

              <tfoot id='O2cbi'></tfoot>

              • <bdo id='O2cbi'></bdo><ul id='O2cbi'></ul>
                  <tbody id='O2cbi'></tbody>
                • <small id='O2cbi'></small><noframes id='O2cbi'>

                  本文介紹了如何在 IE 中從 Javascript 訪問 XHR responseBody(用于二進(jìn)制數(shù)據(jù))?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個(gè)使用 XMLHttpRequest<的網(wǎng)頁/a> 下載二進(jìn)制資源.

                  I've got a web page that uses XMLHttpRequest to download a binary resource.

                  在 Firefox 和 Gecko 中,我可以使用 responseText 來獲取字節(jié),即使字節(jié)流包含二進(jìn)制零.我可能需要用 overrideMimeType() 強(qiáng)制 mimetype 來實(shí)現(xiàn)這一點(diǎn).但是,在 IE 中,responseText 不起作用,因?yàn)樗坪踉诘谝粋€(gè)零處終止.如果您讀取 100,000 個(gè)字節(jié),并且字節(jié) 7 是二進(jìn)制零,您將只能訪問 7 個(gè)字節(jié).IE 的 XMLHttpRequest 公開了一個(gè) responseBody 屬性來訪問字節(jié).我看過一些帖子表明不可能直接從 Javascript 以任何有意義的方式訪問此屬性.這對(duì)我來說聽起來很瘋狂.

                  In Firefox and Gecko I can use responseText to get the bytes, even if the bytestream includes binary zeroes. I may need to coerce the mimetype with overrideMimeType() to make that happen. In IE, though, responseText doesn't work, because it appears to terminate at the first zero. If you read 100,000 bytes, and byte 7 is a binary zero, you will be able to access only 7 bytes. IE's XMLHttpRequest exposes a responseBody property to access the bytes. I've seen a few posts suggesting that it's impossible to access this property in any meaningful way directly from Javascript. This sounds crazy to me.

                  xhr.responseBody 可從 VBScript 訪問,因此顯而易見的解決方法是在網(wǎng)頁的 VBScript 中定義一個(gè)方法,然后從 Javascript 調(diào)用該方法.例如,請(qǐng)參閱 jsdap.不要使用這個(gè) VBScript!!

                  xhr.responseBody is accessible from VBScript, so the obvious workaround is to define a method in VBScript in the webpage, and then call that method from Javascript. See jsdap for one example. DO NOT USE THIS VBScript!!

                  var IE_HACK = (/msie/i.test(navigator.userAgent) && 
                                 !/opera/i.test(navigator.userAgent));   
                  
                  // no no no!  Don't do this! 
                  if (IE_HACK) document.write('<script type="text/vbscript">
                  
                       Function BinaryToArray(Binary)
                  
                           Dim i
                  
                           ReDim byteArray(LenB(Binary))
                  
                           For i = 1 To LenB(Binary)
                  
                               byteArray(i-1) = AscB(MidB(Binary, i, 1))
                  
                           Next
                  
                           BinaryToArray = byteArray
                  
                       End Function
                  
                  </script>'); 
                  
                  var xml = (window.XMLHttpRequest) 
                      ? new XMLHttpRequest()      // Mozilla/Safari/IE7+
                      : (window.ActiveXObject) 
                        ? new ActiveXObject("MSXML2.XMLHTTP")  // IE6
                        : null;  // Commodore 64?
                  
                  
                  xml.open("GET", url, true);
                  if (xml.overrideMimeType) {
                      xml.overrideMimeType('text/plain; charset=x-user-defined');
                  } else {
                      xml.setRequestHeader('Accept-Charset', 'x-user-defined');
                  }
                  
                  xml.onreadystatechange = function() {
                      if (xml.readyState == 4) {
                          if (!binary) {
                              callback(xml.responseText);
                          } else if (IE_HACK) {
                              // call a VBScript method to copy every single byte
                              callback(BinaryToArray(xml.responseBody).toArray());
                          } else {
                              callback(getBuffer(xml.responseText));
                          }
                      }
                  };
                  xml.send('');
                  

                  這是真的嗎?最好的方法?復(fù)制每個(gè)字節(jié)?對(duì)于不會(huì)非常有效的大型二進(jìn)制流.

                  Is this really true? The best way? copying every byte? For a large binary stream that's not going to be very efficient.

                  還有一個(gè)可能技術(shù)使用 ADODB.Stream,它是一個(gè) COM 等效的 MemoryStream.參見此處 示例.它不需要 VBScript,但需要一個(gè)單獨(dú)的 COM 對(duì)象.

                  There is also a possible technique using ADODB.Stream, which is a COM equivalent of a MemoryStream. See here for an example. It does not require VBScript but does require a separate COM object.

                  if (typeof (ActiveXObject) != "undefined" && typeof (httpRequest.responseBody) != "undefined") {
                      // Convert httpRequest.responseBody byte stream to shift_jis encoded string
                      var stream = new ActiveXObject("ADODB.Stream");
                      stream.Type = 1; // adTypeBinary
                      stream.Open ();
                      stream.Write (httpRequest.responseBody);
                      stream.Position = 0;
                      stream.Type = 1; // adTypeBinary;
                      stream.Read....          /// ???? what here
                  }
                  

                  但這不會(huì)很好地工作 - 現(xiàn)在大多數(shù)機(jī)器上都禁用了 ADODB.Stream.

                  But that's not going to work well - ADODB.Stream is disabled on most machines these days.

                  在 IE8 開發(fā)人員工具(相當(dāng)于 Firebug 的 IE)中,我可以看到 responseBody 是一個(gè)字節(jié)數(shù)組,我什至可以看到字節(jié)本身.數(shù)據(jù)就在那兒.我不明白為什么我做不到.

                  In The IE8 developer tools - the IE equivalent of Firebug - I can see the responseBody is an array of bytes and I can even see the bytes themselves. The data is right there. I don't understand why I can't get to it.

                  我可以用 responseText 閱讀它嗎?

                  Is it possible for me to read it with responseText?

                  提示?(除了定義一個(gè) VBScript 方法)

                  hints? (other than defining a VBScript method)

                  推薦答案

                  是的,我在IE中通過XHR讀取二進(jìn)制數(shù)據(jù)的方法是使用VBScript注入.起初這對(duì)我來說很反感,但是,我將其視為更多依賴于瀏覽器的代碼.(常規(guī)的 XHR 和 responseText 在其他瀏覽器中運(yùn)行良好;您可能必須使用 強(qiáng)制 mime 類型XMLHttpRequest.overrideMimeType().這在 IE 上不可用).

                  Yes, the answer I came up with for reading binary data via XHR in IE, is to use VBScript injection. This was distasteful to me at first, but, I look at it as just one more browser dependent bit of code. (The regular XHR and responseText works fine in other browsers; you may have to coerce the mime type with XMLHttpRequest.overrideMimeType(). This isn't available on IE).

                  這就是我如何在 IE 中獲得類似于 responseText 的東西,即使對(duì)于二進(jìn)制數(shù)據(jù)也是如此.首先,一次性注入一些 VBScript,如下所示:

                  This is how I got a thing that works like responseText in IE, even for binary data. First, inject some VBScript as a one-time thing, like this:

                  if(/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)) {
                      var IEBinaryToArray_ByteStr_Script =
                      "<!-- IEBinaryToArray_ByteStr -->
                  "+
                      "<script type='text/vbscript' language='VBScript'>
                  "+
                      "Function IEBinaryToArray_ByteStr(Binary)
                  "+
                      "   IEBinaryToArray_ByteStr = CStr(Binary)
                  "+
                      "End Function
                  "+
                      "Function IEBinaryToArray_ByteStr_Last(Binary)
                  "+
                      "   Dim lastIndex
                  "+
                      "   lastIndex = LenB(Binary)
                  "+
                      "   if lastIndex mod 2 Then
                  "+
                      "       IEBinaryToArray_ByteStr_Last = Chr( AscB( MidB( Binary, lastIndex, 1 ) ) )
                  "+
                      "   Else
                  "+
                      "       IEBinaryToArray_ByteStr_Last = "+'""'+"
                  "+
                      "   End If
                  "+
                      "End Function
                  "+
                      "</script>
                  ";
                  
                      // inject VBScript
                      document.write(IEBinaryToArray_ByteStr_Script);
                  }
                  

                  我正在使用的讀取二進(jìn)制文件的 JS 類公開了一個(gè)有趣的方法,readCharAt(i),它讀取第 i 個(gè)索引處的字符(實(shí)際上是一個(gè)字節(jié)).我是這樣設(shè)置的:

                  The JS class I'm using that reads binary files exposes a single interesting method, readCharAt(i), which reads the character (a byte, really) at the i'th index. This is how I set it up:

                  // see doc on http://msdn.microsoft.com/en-us/library/ms535874(VS.85).aspx
                  function getXMLHttpRequest() 
                  {
                      if (window.XMLHttpRequest) {
                          return new window.XMLHttpRequest;
                      }
                      else {
                          try {
                              return new ActiveXObject("MSXML2.XMLHTTP"); 
                          }
                          catch(ex) {
                              return null;
                          }
                      }
                  }
                  
                  // this fn is invoked if IE
                  function IeBinFileReaderImpl(fileURL){
                      this.req = getXMLHttpRequest();
                      this.req.open("GET", fileURL, true);
                      this.req.setRequestHeader("Accept-Charset", "x-user-defined");
                      // my helper to convert from responseBody to a "responseText" like thing
                      var convertResponseBodyToText = function (binary) {
                          var byteMapping = {};
                          for ( var i = 0; i < 256; i++ ) {
                              for ( var j = 0; j < 256; j++ ) {
                                  byteMapping[ String.fromCharCode( i + j * 256 ) ] =
                                      String.fromCharCode(i) + String.fromCharCode(j);
                              }
                          }
                          // call into VBScript utility fns
                          var rawBytes = IEBinaryToArray_ByteStr(binary);
                          var lastChr = IEBinaryToArray_ByteStr_Last(binary);
                          return rawBytes.replace(/[sS]/g,
                                                  function( match ) { return byteMapping[match]; }) + lastChr;
                      };
                  
                      this.req.onreadystatechange = function(event){
                          if (that.req.readyState == 4) {
                              that.status = "Status: " + that.req.status;
                              //that.httpStatus = that.req.status;
                              if (that.req.status == 200) {
                                  // this doesn't work
                                  //fileContents = that.req.responseBody.toArray(); 
                  
                                  // this doesn't work
                                  //fileContents = new VBArray(that.req.responseBody).toArray(); 
                  
                                  // this works...
                                  var fileContents = convertResponseBodyToText(that.req.responseBody);
                  
                                  fileSize = fileContents.length-1;
                                  if(that.fileSize < 0) throwException(_exception.FileLoadFailed);
                                  that.readByteAt = function(i){
                                      return fileContents.charCodeAt(i) & 0xff;
                                  };
                              }
                              if (typeof callback == "function"){ callback(that);}
                          }
                      };
                      this.req.send();
                  }
                  
                  // this fn is invoked if non IE
                  function NormalBinFileReaderImpl(fileURL){
                      this.req = new XMLHttpRequest();
                      this.req.open('GET', fileURL, true);
                      this.req.onreadystatechange = function(aEvt) {
                          if (that.req.readyState == 4) {
                              if(that.req.status == 200){
                                  var fileContents = that.req.responseText;
                                  fileSize = fileContents.length;
                  
                                  that.readByteAt = function(i){
                                      return fileContents.charCodeAt(i) & 0xff;
                                  }
                                  if (typeof callback == "function"){ callback(that);}
                              }
                              else
                                  throwException(_exception.FileLoadFailed);
                          }
                      };
                      //XHR binary charset opt by Marcus Granado 2006 [http://mgran.blogspot.com] 
                      this.req.overrideMimeType('text/plain; charset=x-user-defined');
                      this.req.send(null);
                  }
                  

                  轉(zhuǎn)換碼由Miskun提供.

                  非常快,效果很好.

                  我使用這種方法從 Javascript 中讀取和提取 zip 文件,并在一個(gè)用 Javascript 讀取和顯示 EPUB 文件的類中.很合理的表現(xiàn).一個(gè) 500kb 的文件大約需要半秒.

                  I used this method to read and extract zip files from Javascript, and also in a class that reads and displays EPUB files in Javascript. Very reasonable performance. About half a second for a 500kb file.

                  這篇關(guān)于如何在 IE 中從 Javascript 訪問 XHR responseBody(用于二進(jìn)制數(shù)據(jù))?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

                  【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會(huì)等待 ajax 調(diào)用完成)
                  JavaScript innerHTML is not working for IE?(JavaScript innerHTML 不適用于 IE?)
                  XMLHttpRequest cannot load, No #39;Access-Control-Allow-Origin#39; header is present on the requested resource(XMLHttpRequest 無法加載,請(qǐng)求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請(qǐng)求是否有可能不遵循重定向 (301 302))
                  NETWORK_ERROR: XMLHttpRequest Exception 101(NETWORK_ERROR:XMLHttpRequest 異常 101)
                  XMLHttpRequest 206 Partial Content(XMLHttpRequest 206 部分內(nèi)容)

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

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

                      <tfoot id='Yzp4p'></tfoot>
                        <tbody id='Yzp4p'></tbody>

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

                          • <bdo id='Yzp4p'></bdo><ul id='Yzp4p'></ul>
                          • 主站蜘蛛池模板: 日韩成人免费在线视频 | 久久国内精品 | 99视频在线播放 | 国产成人精品午夜视频免费 | 久久r免费视频 | 欧美日韩久久精品 | 国产精品自在线 | 日韩福利一区 | 91久久国产综合久久 | 毛片入口 | 福利视频亚洲 | 亚洲综合视频一区 | 性视频网| 黄色网址av | 国产你懂的在线观看 | 中文字幕啪啪 | 在线日韩不卡 | 日韩欧美在 | 亚洲一区网站 | 奇米超碰 | 伊大人久久 | 日日噜噜噜夜夜爽爽狠狠视频, | 国产精品久久久久久一区二区三区 | 国产精品久久久久久久久久久久久久 | 国产精品高潮呻吟久久av野狼 | 免费一区二区 | 久久国产精品色av免费观看 | 亚洲高清网 | 久久久久久久久久久爱 | 欧美日韩精品久久久免费观看 | 日韩精品免费视频 | 91久久久久久| 九九热这里 | 99热视 | 国产精品国产a级 | 影音先锋成人资源 | 91精品久久 | 成人免费片 | а_天堂中文最新版地址 | 水蜜桃亚洲一二三四在线 | 亚洲欧美综合网 |