有个项目中要跳转到另外一个项目,还需要带参数
考虑到安全性的问题,最好是用POST跳转,不能再URL中拼参
所以找到了这个方法
直接在JS中模拟form表单POST提交
1 1 function toQrPay() { 2 2 3 3 var parames = new Array(); 4 4 parames.push({ name: "userName", value: "admin88"}); 5 5 parames.push({ name: "token", value: "token"}); 6 6 7 7 Post("http://localhost:8080/qrPay/sys/tokenLogin", parames); 8 8 9 9 return false; 1010 } 1111 1212 /* 1313 *功能: 模拟form表单的提交 1414 *参数: URL 跳转地址 PARAMTERS 参数 1515 */ 1616 function Post(URL, PARAMTERS) { 1717 //创建form表单 1818 var temp_form = document.createElement("form"); 1919 temp_form.action = URL; 2020 //如需打开新窗口,form的target属性要设置为'_blank' 2121 temp_form.target = "_self"; 2222 temp_form.method = "post"; 2323 temp_form.style.display = "none"; 2424 //添加参数 2525 for (var item in PARAMTERS) { 2626 var opt = document.createElement("textarea"); 2727 opt.name = PARAMTERS[item].name; 2828 opt.value = PARAMTERS[item].value; 2929 temp_form.appendChild(opt); 3030 } 3131 document.body.appendChild(temp_form); 3232 //提交数据 3333 temp_form.submit(); 3434 }