繁体   English   中英

客户端的异步JavaScript函数(如何编写回叫)

[英]Async JavaScript Function on Client Side( how to write call back)

我基本上面临一个问题,我有一个长期运行的任务,读取编码的字节,然后解析字节以在其中查找数据。

  functionLongRunningTask() {
  //bytes returned from office.js (GetFileAsync Method)
  var documentText = OSF.OUtil.encodeBase64(resultSlice.value.data);

   // Open the document, which is stored as a base64 string.
   var doc = new openXml.OpenXmlPackage(documentText);
   var customXMLpart = doc.getPartByUri("/customXml/item1.xml");

    if (customXMLpart == 'undefined' || customXMLpart == null) {
     window.location = 'Page1.aspx'
      }
      else {
      if (window.DOMParser) {
       var parser = new DOMParser();
      xmlDoc = parser.parseFromString(customXMLpart.data, "text/xml");
       }
          var customxml = xmlDoc.getElementsByTagName("DocumentID");
             var documentid = 0;
        for (var i = 0; i < customxml.length; i++) {
               documentid = customxml[i].textContent;
                   }
            window.location = 'Page2.aspx?documentid=' + documentid;
                      }
  }

所有读取和遍历都是在客户端完成的,而没有服务器端参与。 现在,当我以同步方式运行此长时间运行的任务时,我的应用程序在Office Word 2013(基本上是Office APP)中运行。 UI被冻结并停止响应,并重新启动Office APP。

我需要以异步方式进行操作,因此UI不会冻结,我正在使用HTML5和IE 9+。 任何帮助将不胜感激

问候

您将无法访问WebWorker中的DOM分析器,因此该方法不适用。 您将需要在计时器事件上运行部分代码。

这是一个可以帮助计时器运行代码的库-> https://github.com/jameswestgate/taskjs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM