zoukankan      html  css  js  c++  java
  • 利用jQuery 通用文件导出前端实现,MVC文件导出

    /**
     * 下载文件
     * @param options
     * =============================
     *  downLoadFile({
     *      url:'', //下载地址
     *      data:{"id":"4f4fa1d55b114d8cb9a5e46d13b5e5bc"},//请求参数
     *      isNewWinOpen:false,//是否新窗口打开
     *      method:'post'
     *  });
     *
     *
     * =============================
     */
    function downLoadFile(options) {
        var config = $.extend(true, {
            method: 'post',
            isNewWinOpen: false,
            onLoad:function () {
    
            }
        }, options);
        var frameName = 'downloadFrame_' + new Date().getTime();
        var $iframe = $('<div style="display: none"><iframe name="' + frameName + '" src="about:blank"></iframe></div>');
        var $form = $('<form target="' + frameName + '" method="' + config.method + '" action="' + config.url + '"></form>');
        if (config.isNewWinOpen) {
            $form.attr("target", "_blank");
        }
        $iframe.children().load(function () {
            try {
                var jsonStr = $(this).contents('body').text();
                var jsonObj;
                if(jsonStr!=''){
                    jsonObj= JSON.parse(jsonStr);
                    config.onLoad(jsonObj);
                }
            } catch (e) {
    
            }
            setTimeout(function () {
                $(this).parent().remove();
            }.bind(this), 3000);
        });
        /*拼接参数*/
        for (var key in config.data) {
            $form.append('<input type="hidden" name="' + key + '" value="' + config.data[key] + '" />');
        }
        $iframe.append($form);
        $('body').append($iframe);
        $form.submit();
    }
  • 相关阅读:
    es index template
    什么是元类
    Normal Data Structure Tricks
    Python 学习笔记
    点分治
    人类智慧贪心
    「JOI 2021 Final」地牢 3
    【美团杯2020】魔塔
    CF917D 的垃圾做法
    【ULR #2】Picks loves segment tree IX
  • 原文地址:https://www.cnblogs.com/yeminglong/p/12105936.html
Copyright © 2011-2022 走看看