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.
- remove inline onclick submit
- add onsubmit handler form
- 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
Post a Comment