當我點擊按鈕時,需要使用jQuery ajax添加GET參數。比如有一個代碼使用JSP getParameter和JQuery GET ajax時出現錯誤
<button id="20" class="click">Click me</button>
<button id="21" class="click">Click me</button>
<button id="22" class="click">Click me</button>
通過點擊特定的按鈕,我需要通過按鈕ID
myapp.com/mainpage.jsp?check=20
但是,它應該使用JQuery AJAX API是工作。我的意思是,param不應該在URL中可見,因爲每當我將要更改check
值時,此操作將刷新頁面,我不需要它。我寫了這樣的代碼:
$(document).ready(function() {
$(".btn-info").click(function() {
$.ajax({
url: "stuff",
type: "GET",
data:{ checkId: this.id },
success: function(response) {
console.log("success: " + response);
},
error: function(xhr) {
console.log("error exception: " + xhr);
}
});
});
});
而在最後,我添加了JSP代碼
My result: <%= request.getParameter("checkId") %>
當我通過特定的按鈕點擊,例如通過按鈕
<button id="20" class="click">Click me</button>
在瀏覽器日誌我看到一個值爲20的html文檔:
而這正確!但頁面上這個數值並沒有改變,仍然爲空:
你能告訴我請,爲什麼會發生,以及我在做什麼錯?
注:忘了,要改變.btn-信息來。點擊,但問題不) – torori