javascript - call the java method using ajax on button click -


i have button in blank.jsp (lets say).

<input class="submit_button" type="submit" id="btnpay" name="btnpay" value="payment"  style="position: absolute; left: 350px; top: 130px;" onclick="javascript:payment();"> 

when button clicked need call java method callprocedure() using ajax.

function payment()     {         alert('payment done successfully...');         ........         // ajax method call java method "callprocedure()"         ........     } 

i new ajax. how can call java method using ajax. please me soon. in advance.

  1. remove inline onclick submit
  2. add onsubmit handler form
  3. cancel submission

i recommend jquery when have ajax involved

i assume here servlet function in form tag. if not, exchange this.action servlet name

$(function() {   $("#formid").on("submit",function(e) { // pass event     e.preventdefault(); // cancel submission     $.post(this.action,$(this).serialize(),function(data) {       $("#resultid").html(data); // show result in id="resultid"       // if servlet not produce response, can show message       // $("#resultid").html("payment succeeded");     });   }); }); 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -