有個項目中要跳轉到另外一個項目,還需要帶參數
考慮到安全性的問題,最好是用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 }