$('#comment').on('submit', function(e) {
e.preventDefault();
var name = $('#name').val();
var message = $('#message').val();
var postid = $('#post_id').val();
$.ajax({
type: "POST",
url: host+'/comment/add',
data: {name:name, message:message, post_id:postid}
success: function( msg ) {
alert( msg );
}
});
});
// First add jquery
// <script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
$(document).ready(function() {
$("#myForm").on('submit', (function(e) {
e.preventDefault();
$.ajax({
url: $(this).attr('action'),
type: "POST",
data: new FormData(this),
contentType: false,
cache: false,
processData: false,
success: function(response) {
$("#myForm").trigger("reset"); // this line is to reset form input fields
alert('submitted');
},
error: function(e) {
alert('Failed to sumit');
}
});
}));
});
//don't forget to add csrf token