有个项目中要跳转到另外一个项目,还需要带参数
考虑到安全性的问题,最好是用POST跳转,不能再URL中拼参
所以找到了这个方法
直接在JS中模拟form表单POST提交
1 function toQrPay() { 2 3 var parames = new Array(); 4 parames.push({ name: "userName", value: "admin88"}); 5 parames.push({ name: "token", value: "token"}); 6 7 Post("http://localhost:8080/qrPay/sys/tokenLogin", parames); 8 9 return false; 10 } 11 12 /* 13 *功能: 模拟form表单的提交 14 *参数: URL 跳转地址 PARAMTERS 参数 15 */ 16 function Post(URL, PARAMTERS) { 17 //创建form表单 18 var temp_form = document.createElement("form"); 19 temp_form.action = URL; 20 //如需打开新窗口,form的target属性要设置为'_blank' 21 temp_form.target = "_self"; 22 temp_form.method = "post"; 23 temp_form.style.display = "none"; 24 //添加参数 25 for (var item in PARAMTERS) { 26 var opt = document.createElement("textarea"); 27 opt.name = PARAMTERS[item].name; 28 opt.value = PARAMTERS[item].value; 29 temp_form.appendChild(opt); 30 } 31 document.body.appendChild(temp_form); 32 //提交数据 33 temp_form.submit(); 34 }