Js生成表单使用post提交方式带参数下载文件,页面不跳转

 postFile(params, url) { 
        var form = document.createElement("form");
        form.style = "display:none;";
        form.action = url;
        form.method = "post";
        form.target = "form_iframe"
        document.body.appendChild(form);
       if(!document.getElementById("form_iframe")){
          var ifreame = document.createElement("iframe")
          ifreame.id = "form_iframe";
          ifreame.name = "form_iframe";
          ifreame.style ="display:none;"
          document.body.appendChild(ifreame);
       }
        // 动态创建input并给value赋值
        for (var key in params) {
          var input = document.createElement("input");
          input.type = "hidden";
          input.name = key;
          input.value = params[key];
          form.appendChild(input);
        }
        form.submit();
        form.remove();
      }
    },

 

posted @ 2020-03-10 11:13  一月1  阅读(1626)  评论(0编辑  收藏  举报