How to read external docx file content using ajax

不羁的心 提交于 2019-12-08 15:29:30

问题


The following is the request formed:

Request URL: https://remoteserverurl.docx Request Method: GET Status Code: 200 OK Remote Address: 10.232.4.216:7317 Referrer Policy: no-referrer-when-downgrade Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,/;q=0.8 Accept-Encoding: gzip, deflate, br Accept-Language: en-US,en;q=0.9 Connection: keep-alive Cookie: isPageflowTouch=true; schemaId=1; updCtx=true; typeId=91433788276151561974313054830 Host: domain.test.com Upgrade-Insecure-Requests: 1 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36


回答1:


function getdocx(url){
var oReq = new XMLHttpRequest();
var arrayBuffer;
oReq.open('GET', url, true);
oReq.responseType = "arraybuffer";
oReq.onload = function (oEvent) {
  arrayBuffer = oReq.response; // Note: not oReq.responseText
   var binary = '';
   var bytes = new Uint8Array( arrayBuffer );
   var len = bytes.byteLength;
 for (var i = 0; i < len; i++) {
    binary += String.fromCharCode( bytes[ i ] );
 }
var contentfromDocx = window.btoa( binary );
//do what ever you want with this
oReq.send(null);

}



来源:https://stackoverflow.com/questions/51988304/how-to-read-external-docx-file-content-using-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!