pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

  • <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="h5p7pdr" 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="zrvpzpj" 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ù))?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

                  問題描述

                  我有一個使用 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 來實現(xiàn)這一點.但是,在 IE 中,responseText 不起作用,因為它似乎在第一個零處終止.如果您讀取 100,000 個字節(jié),并且字節(jié) 7 是二進(jìn)制零,您將只能訪問 7 個字節(jié).IE 的 XMLHttpRequest 公開了一個 responseBody 屬性來訪問字節(jié).我看過一些帖子表明不可能直接從 Javascript 以任何有意義的方式訪問此屬性.這對我來說聽起來很瘋狂.

                  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 中定義一個方法,然后從 Javascript 調(diào)用該方法.例如,請參閱 jsdap.不要使用這個 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ù)制每個字節(jié)?對于不會非常有效的大型二進(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.

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

                  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
                  }
                  

                  但這不會很好地工作 - 現(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 是一個字節(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?

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

                  hints? (other than defining a VBScript method)

                  推薦答案

                  是的,我在IE中通過XHR讀取二進(jìn)制數(shù)據(jù)的方法是使用VBScript注入.起初這對我來說很反感,但是,我將其視為更多依賴于瀏覽器的代碼.(常規(guī)的 XHR 和 responseText 在其他瀏覽器中運行良好;您可能必須使用 強(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 的東西,即使對于二進(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 類公開了一個有趣的方法,readCharAt(i),它讀取第 i 個索引處的字符(實際上是一個字節(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 文件,并在一個用 Javascript 讀取和顯示 EPUB 文件的類中.很合理的表現(xiàn).一個 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ù))?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關(guān)文檔推薦

                  Browser waits for ajax call to complete even after abort has been called (jQuery)(即使在調(diào)用 abort (jQuery) 之后,瀏覽器也會等待 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 無法加載,請求的資源上不存在“Access-Control-Allow-Origin標(biāo)頭) - IT屋-程序員軟件開發(fā)技術(shù)分
                  Is it possible for XHR HEAD requests to not follow redirects (301 302)(XHR HEAD 請求是否有可能不遵循重定向 (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="dbl7drl" id='Yzp4p'><tfoot id='Yzp4p'></tfoot><dl id='Yzp4p'><fieldset id='Yzp4p'></fieldset></dl></div>

                          • <bdo id='Yzp4p'></bdo><ul id='Yzp4p'></ul>
                          • 主站蜘蛛池模板: 油液红外光谱仪-油液监测系统-燃油嗅探仪-上海冉超光电科技有限公司 | 海外整合营销-独立站营销-社交媒体运营_广州甲壳虫跨境网络服务 焊管生产线_焊管机组_轧辊模具_焊管设备_焊管设备厂家_石家庄翔昱机械 | 气密性检测仪_气密性检测设备_防水测试仪_密封测试仪-岳信仪器 | 广州市哲铭油墨涂料有限公司,水性漆生产研发基地 | 「银杏树」银杏树行情价格_银杏树种植_山东程锦园林 | 二氧化碳/活性炭投加系统,次氯酸钠发生器,紫外线消毒设备|广州新奥 | 3dmax渲染-效果图渲染-影视动画渲染-北京快渲科技有限公司 | 旋转/数显粘度计-运动粘度测定仪-上海平轩科学仪器 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-沼河浸过滤器 | BESWICK球阀,BESWICK接头,BURKERT膜片阀,美国SEL继电器-东莞市广联自动化科技有限公司 | 不锈钢列管式冷凝器,换热器厂家-无锡飞尔诺环境工程有限公司 | 盘古网络技术有限公司| 小学教案模板_中学教师优秀教案_高中教学设计模板_教育巴巴 | 中空玻璃生产线,玻璃加工设备,全自动封胶线,铝条折弯机,双组份打胶机,丁基胶/卧式/立式全自动涂布机,玻璃设备-山东昌盛数控设备有限公司 | 机械加工_绞车配件_立式离心机_减速机-洛阳三永机械厂 | 自恢复保险丝_贴片保险丝_力特保险丝_Littelfuse_可恢复保险丝供应商-秦晋电子 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 定制异形重型钢格栅板/钢格板_定做踏步板/排水沟盖板_钢格栅板批发厂家-河北圣墨金属制品有限公司 | 艺术涂料|木纹漆施工|稻草漆厂家|马来漆|石桦奴|水泥漆|选加河南天工涂料 | 附着力促进剂-尼龙处理剂-PP处理剂-金属附着力处理剂-东莞市炅盛塑胶科技有限公司 | 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 - 杭州标识标牌|文化墙|展厅|导视|户内外广告|发光字|灯箱|铭阳制作公司 | 气弹簧定制-气动杆-可控气弹簧-不锈钢阻尼器-工业气弹簧-可调节气弹簧厂家-常州巨腾气弹簧供应商 | 油冷式_微型_TDY电动滚筒_外装_外置式电动滚筒厂家-淄博秉泓机械有限公司 | 挤塑板-XPS挤塑板-挤塑板设备厂家[襄阳欧格] | 网站优化公司_北京网站优化_抖音短视频代运营_抖音关键词seo优化排名-通则达网络 | 庭院灯_太阳能景观灯_草坪灯厂家_仿古壁灯-重庆恒投科技 | 便携式表面粗糙度仪-彩屏硬度计-分体式粗糙度仪-北京凯达科仪科技有限公司 | 药品仓库用除湿机-变电站用防爆空调-油漆房用防爆空调-杭州特奥环保科技有限公司 | 铝合金线槽_铝型材加工_空调挡水板厂家-江阴炜福金属制品有限公司 | 高铝矾土熟料_细粉_骨料_消失模_铸造用铝矾土_铝酸钙粉—嵩峰厂家 | 火锅加盟_四川成都火锅店加盟_中国火锅连锁品牌十强_朝天门火锅【官网】 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 智能终端_RTU_dcm_北斗星空自动化科技 | 工业插头-工业插头插座【厂家】-温州罗曼电气| 最新范文网_实用的精品范文美文网| 橡胶接头|可曲挠橡胶接头|橡胶软接头安装使用教程-上海松夏官方网站 | 大型低温冷却液循环泵-低温水槽冷阱「厂家品牌」京华仪器_京华仪器 | 电力测功机,电涡流测功机,磁粉制动器,南通远辰曳引机测试台 | 深圳市源和塑胶电子有限公司-首页 | 采暖炉_取暖炉_生物质颗粒锅炉_颗粒壁炉_厂家加盟批发_烟台蓝澳采暖设备有限公司 | 成都LED显示屏丨室内户外全彩led屏厂家方案报价_四川诺显科技 |