我正在嘗試使用 _GET 方法動(dòng)態(tài)獲取查詢參數(shù)。我的功能看起來(lái)像這樣:var baseURL = "http://example.org";// clears the last query paramshistory.pushState("", document.title, baseURL);// retrieves the value from the HTML codevar value = document.getElementById('id').value;// URL with updated query paramsvar updatedURL = document.URL + "?value=" + value;// pushing the new URL without refreshing the page.history.pushState("", document.title, updatedURL);// URL looks something like this "http://example.org?value=1"但是當(dāng)我嘗試使用_GET['value']從 URL 檢索值時(shí),它只獲取頁(yè)面初始化的值并且不會(huì)動(dòng)態(tài)更新,有沒(méi)有什么方法可以在不刷新頁(yè)面的情況下檢索這個(gè)值?
1 回答

森林海
TA貢獻(xiàn)2011條經(jīng)驗(yàn) 獲得超2個(gè)贊
history.pushState()只需更改瀏覽器 URL 的值。它實(shí)際上并不發(fā)出服務(wù)器請(qǐng)求并加載 _GET 變量。這就是您無(wú)法訪問(wèn)它們的原因。
要在不刷新頁(yè)面的情況下執(zhí)行此操作,您需要進(jìn)行 ajax 調(diào)用。
$.ajax({
type: "GET",
url: "yourpage.php",
data: {value:value},
cache: false,
success: function(result){
// do something with the returned data
}
});
- 1 回答
- 0 關(guān)注
- 126 瀏覽
添加回答
舉報(bào)
0/150
提交
取消