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>
                          • 主站蜘蛛池模板: 安徽合肥格力空调专卖店_格力中央空调_格力空调总经销公司代理-皖格制冷设备 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 超声波乳化机-超声波分散机|仪-超声波萃取仪-超声波均质机-精浩机械|首页 | 烽火安全网_加密软件、神盾软件官网 | 插针变压器-家用电器变压器-工业空调变压器-CD型电抗器-余姚市中驰电器有限公司 | 深圳高新投三江工业消防解决方案提供厂家_服务商_园区智慧消防_储能消防解决方案服务商_高新投三江 | Q361F全焊接球阀,200X减压稳压阀,ZJHP气动单座调节阀-上海戎钛 | 新能源汽车教学设备厂家报价[汽车教学设备运营18年]-恒信教具 | 企业彩铃制作_移动、联通、电信集团彩铃上传开通_彩铃定制_商务彩铃管理平台-集团彩铃网 | 呼末二氧化碳|ETCO2模块采样管_气体干燥管_气体过滤器-湖南纳雄医疗器械有限公司 | 江苏全风,高压风机,全风环保风机,全风环形高压风机,防爆高压风机厂家-江苏全风环保科技有限公司(官网) | 青州开防盗门锁-配汽车芯片钥匙-保险箱钥匙-吉祥修锁店 | 保温杯,儿童婴童奶瓶,运动水壶「广告礼品杯定制厂家」超朗保温杯壶 | 宁夏档案密集柜,智能密集柜,电动手摇密集柜-盛隆柜业宁夏档案密集柜厂家 | 天津货架厂_穿梭车货架_重型仓储货架_阁楼货架定制-天津钢力仓储货架生产厂家_天津钢力智能仓储装备 | 亮点云建站-网站建设制作平台| 客服外包专业服务商_客服外包中心_网萌科技 | 除尘布袋_液体过滤袋_针刺毡滤料-杭州辉龙过滤技术有限公司 | 郑州爱婴幼师学校_专业幼师培训_托育师培训_幼儿教育培训学校 | ASA膜,ASA共挤料,篷布色母料-青岛未来化学有限公司 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 辐射色度计-字符亮度测试-反射式膜厚仪-苏州瑞格谱光电科技有限公司 | 重庆私家花园设计-别墅花园-庭院-景观设计-重庆彩木园林建设有限公司 | 粉丝机械,粉丝烘干机,粉丝生产线-招远市远东粉丝机械有限公司 | 赛默飞Thermo veritiproPCR仪|ProFlex3 x 32PCR系统|Countess3细胞计数仪|371|3111二氧化碳培养箱|Mirco17R|Mirco21R离心机|仟诺生物 | 巩义市科瑞仪器有限公司| 臭氧发生器_臭氧消毒机 - 【同林品牌 实力厂家】 | 热处理炉-退火炉-回火炉设备厂家-丹阳市电炉厂有限公司 | ETFE膜结构_PTFE膜结构_空间钢结构_膜结构_张拉膜_浙江萬豪空间结构集团有限公司 | 高压无油空压机_无油水润滑空压机_水润滑无油螺杆空压机_无油空压机厂家-科普柯超滤(广东)节能科技有限公司 | 进口便携式天平,外校_十万分之一分析天平,奥豪斯工业台秤,V2000防水秤-重庆珂偌德科技有限公司(www.crdkj.com) | 洗地机_全自动洗地机_手推式洗地机【上海滢皓环保】 | 合肥角钢_合肥槽钢_安徽镀锌管厂家-昆瑟商贸有限公司 | 淘剧影院_海量最新电视剧,免费高清电影随心观看 | 烟台金蝶财务软件,烟台网站建设,烟台网络推广 | 在线PH计-氧化锆分析仪-在线浊度仪-在线溶氧仪- 无锡朝达 | 团建-拓展-拓展培训-拓展训练-户外拓展训练基地[无锡劲途] | 超声波成孔成槽质量检测仪-压浆机-桥梁预应力智能张拉设备-上海硕冠检测设备有限公司 | 成都办公室装修-办公室设计-写字楼装修设计-厂房装修-四川和信建筑装饰工程有限公司 | 专业生物有机肥造粒机,粉状有机肥生产线,槽式翻堆机厂家-郑州华之强重工科技有限公司 | 石栏杆_青石栏杆_汉白玉栏杆_花岗岩栏杆 - 【石雕之乡】点石石雕石材厂 |