I'm new to AJAX. i want to call AJAX function when i click a button using onclick() event. This is the AJAX function called by onclick() event
function onclickFunction(aId){
$.ajax({
type: "get",
url: "like_audio",
data: {
aId:aId
},
success: function (data){
alert(data);
},
error: function (xhr, ajaxOptions, thrownError){
}
});
return false;
}
This is how i'm calling the onclick() event
<a href="" onclick=onclickFunction(id)
Just get the use return inside onclick
, which will prevent the reload.
<a href="" onclick="return onclickFunction('id')">a</a>
As an alternative you can use
<a href="javascript:onclickFunction('id')">a</a>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With