解决前端对应后台的导出接口 window.open()提交数据 参数过长的问题

一般 window.open 传参数都是用Get.方式,在url后面拼接参数。
但这样有时候并不适用,如:
1)不想被看到参数信息
2)参数过长,get有限制会被截断
3)可能有中文编码问题
所以需要用post方式 ,下面说的就是一种window.open发送post请求的方法。

网页的post一般是通过form表单的方式来实现的,所以现在来模拟form表单的方式来实现window.open效果。

  var winHeight = window.document.documentElement.clientHeight - 10;
  // 后台写好的导出功能接口
  var url = basePath + "/Search/export";  
  // 这里创建from表单  设置input隐藏域 携带需要的参数 注意这里要加密(中文要乱码)  后后台接收要解码 URLDecoder.decode(request.getParameter("jsonData"),"UTF-8");
  var formStr = '<form style="visibility:hidden;" method="POST" action="' + url + '">' +
  '<input type="hidden" name="listID" value="' + encodeURIComponent(listsum) + '" />' +
  '<input type="hidden" name="username" value="' + encodeURIComponent(username) + '" />' +'</form>';
  
  var win = window.open("",  "height=" + winHeight+ ",top=80,left=80,toolbar=no, menubar=no, scrollbars=yes, resizable=yes");
  
  win.document.body.innerHTML = formStr;
  
  win.document.forms[0].submit();

亲测有效,希望可以帮到你们。

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值