Javascript 导出excel时如何显示加载(处理)?

Javascript 导出excel时如何显示加载(处理)?,javascript,jquery,ajax,Javascript,Jquery,Ajax,单击导出excel选项时,对后端代码的调用将从服务器端获取文件(file_name.xls),该文件通过document.location.href下载 jQuery("#exportExcel").click(function() { $("#loading").show(); var exportExcelUrl='/portal/portalDownloadExcel?fileType=main';

单击导出excel选项时,对后端代码的调用将从服务器端获取文件(file_name.xls),该文件通过
document.location.href
下载

jQuery("#exportExcel").click(function() {
                    $("#loading").show();
                    var exportExcelUrl='/portal/portalDownloadExcel?fileType=main';
                    document.location.href=exportExcelUrl;
                    $("#loading").hide();

        });
但上面的步骤无法隐藏处理映像,因为我没有得到服务器的响应

我试图显示加载,但文件下载的所有内容都有特殊字符。
为了删除这些特殊字符,我使用了:'encodeURIComponent,blob,special characters remover'

我使用AngularJS并为报表创建特定服务:

    app.factory('Report', function ($q, $sce, $http, API_LINK) {
  var report = {
    getTypes: function () {
      return [
        {name: 'html', title: 'HTML'},
        {name: 'pdf', title: 'PDF'},
        {name: 'excel', title: 'Excel'}
      ]
    },
    get: function (name, type, params, returnResult) {
      var html = type === 'html';
      params = params ? params : {};
      var p = {
        params: params,
        name: name,
        type: type
      };
      var url = API_LINK + 'report?' + $.param(p);

      var config = {
        method: 'GET',
        url: url
      };
      if (!html) {
        config.responseType = 'arraybuffer';
      }
      var http = $http(config);
      if (returnResult) {
        var deferred = $q.defer();
        http.error(function () {
          deferred.reject();
        });
      }
      http.success(
        function (data, status, headers) {
          if (returnResult) {
            return deferred.resolve($sce.trustAsHtml(data));
          }
          var type = headers('Content-Type');
          if (html) {
            var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
            var win;
            if (isFirefox) {
              win = window.open('');
            } else {
              var params = ['height=' + screen.height, 'width=' + screen.width, 'fullscreen=yes'];
              win = window.open('', '_newtab', params.join(','));
            }
            if (win) {
              win.moveTo(0, 0);
              win.document.write(data);
              win.focus();
            } else {
              alert('Please allow popups for this site');
            }
          } else {
            var contentDisposition = headers('Content-disposition');
            var filename = 'Report ' + (new Date).toShortString() + ' ' + (new Date).toShortTimeString() + '.';
            if (type = 'application-pdf') {
              filename += 'pdf';
            }
            if (angular.isString(contentDisposition)) {
              filename = contentDisposition.split('"')[1];
            }
            var file = new Blob([data], {type: type});
            saveAs(file, filename);
          }
        });
      if (returnResult) {
        return deferred.promise;
      }
    }
  };
  return report;
});

也许这将帮助您

ZAYEC77谢谢,但我只使用jquery,您可以尝试jquery。我尤其需要一种方法,在单击导出时实现加载/处理符号,直到获得保存选项。您可以使用