javascript - Something wrongs with JSP getParameter and JQuery GET ajax -


i need add parameters using jquery ajax when click on button. example there code

<button id="20" class="click">click me</button> <button id="21" class="click">click me</button> <button id="22" class="click">click me</button> 

by clicking on specific button need pass button id

myapp.com/mainpage.jsp?check=20 

but, should work using jquery ajax api. mean, param should not visible in url, because each time when changing check value, action refresh page, needn't it. wrote code this:

$(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);                         }                     });                 });             }); 

and in end, added jsp code

my result: <%= request.getparameter("checkid") %> 

when click specific button, example button

<button id="20" class="click">click me</button> 

in browser logs saw html document value 20:

enter image description here

and correct! on page value didn't change , still null:

enter image description here

could tell me please, why happens, , i'm doing wrong?

this not true way thing u want.

first should send request servlet (doget method of servlet). , servlet return 'response' value jsp. in success part of ajax function can change value of true result

$(document).ready(function() {   $(".btn-info").click(function() {     $.ajax({       url: "stuff",       type: "get",       data: {         checkid: this.id       },       success: function(response) {         console.log("success: " + response);         $('#trueresult').html(response);       },       error: function(xhr) {         console.log("error exception: " + xhr);       }     });   }); }); 
true result <span id="trueresult"></span> 

Comments