I have a button named "insert comment". When user clicks on it, form will be submit (using ajax) and insert a new comment in the database. Now my problem is when user clicks twice (quickly) on this button, comment will be insert two time.
Now I want to prevent of inserting again, I mean is I want to disable all event while ajax process is working... Is it possible?
Here is my code:
$("#bottunId").click(function(){
$("#form-"+pure_id).submit(function(e){
e.preventDefault(e);
comment(pure_id);
});
});
function comment(pure_id){
$("#textarea-"+pure_id).animate({opacity: 0.5}, 0);
var frm = $('#form-'+pure_id);
$.ajax({
url : frm.attr('action'),
type : frm.attr('method'),
data : frm.serialize(),
dataType : 'JSON',
success : function (commenting_system) {
if(commenting_system.error_msg){
$(".error_msg").html(commenting_system.error_msg); $(".error").fadeIn(200);
close_error_msg = setTimeout(function(){ $(".error").fadeOut(100); }, 5000);
$("#textarea-"+pure_id).animate({opacity: 1}, 0);
}
else{
$("#table-"+pure_id).append('<tr><td>new row</td></tr>');
$("#textarea-"+pure_id).animate({opacity: 1}, 0);
}
} // for success
}); // for ajax
} // function comment