// jquery code
$(document).ready(function () {
$(document).on("click","#cmt-add", function (){
alert("hello");
e.preventDefault();
var frm = $('#frm');
$.ajax({
type: 'POST',
url: 'add_comment_ajax.php',
data: frm.serialize(),
success: function (data) {
$("#done").html("confession added!!");
}, error: function(jqXHR, textStatus, errorThrown){
console.log(" The following error occured: "+ textStatus, errorThrown);
} });
return false;
})
});
// html code load by ajax
<form id="frm" method="post" action="add_comment_ajax.php">
<input type="hidden" value="<?php echo $run->ID; ?>" name="id">
<input type="text" name='cmt' class="w3-input" placeholder="Comment">
<input type="text" name="name" placeholder="Name(if you want!!)">
<button id="submit_cmt" class="w3-button w3-white w3-border w3-border-blue w3-input">Comment(<?php commet_count($run->ID); ?>)
</button>
</form>
<div id="done"></div>