GET 方式
window.location.href是我們常用來在js中實現頁面跳轉的方法,這是使用get方式發送請求,示例如下
window.location.href = url;
優點是簡單易用,缺點是如果有參數的話,參數會暴露在url地址中,這降低了系統的安全性,也影響用戶體驗。
POST 方式
通過模擬表單提交的方式進行跳轉
// 發送POST請求跳轉到指定頁面
function httpPost(URL, PARAMS) {var temp = document.createElement("form");temp.action = URL;temp.method = "post";temp.style.display = "none";for (var x in PARAMS) {var opt = document.createElement("textarea");opt.name = x;opt.value = PARAMS[x];temp.appendChild(opt);}document.body.appendChild(temp);temp.submit();return temp;
}var params = {"aValue": 'a',"bValue": 'b',
};httpPost("/nexturl", params);