$(document).ready(function(){ $(document).on('click','.submitComment',function(e) { e.preventDefault(); //send ajax request var form = $(this).closest('form'); var formValue = $(this).closest('form').val(); if (formValue.length > 0) { $.ajax({ url: 'ajax_comment.php', type: 'POST', cache: false, dataType: 'json', data: $(form).serialize(), //form serialize data beforeSend: function(){ //Changeing submit button value text and disableing it $(this).val('Submiting ....').attr('disabled', 'disabled'); }, success: function(data) { var item = $(data.html).hide().fadeIn(800); $('.comment-block_' + data.id).append(item); // reset form and button $(form).trigger('reset'); $(this).val('Submit').removeAttr('disabled'); }, error: function(e) { alert(e); } }); } else { alert("Please fill in the form"); } }); });
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)