i try to make comment system in posts if user submit the form the function will start and ajax request send put if he click submit quickly more one time the function will be fire more one time and that will case comment redundancy
i want to stop form submit until the first request finish
the form code is
<form method="post" action="addcomment.php" onsubmit="addreqcomment(<? =$request->id);">
<input type="text" name="comment" id="comm_area-<?=$request->id?>" class="input-block-level autosize-normal" placeholder="home.add comment..." required/>
</form>
the JavaScript function:
function addreqcomment(id){
var comment=$.trim( $('#comm_area-'+id).val() );
if(comment==''){
alert("please enter comment");
return false;
}
$.post("addcomment.php",{comment:comment,request_id:id},function(data){
if(data=='error'){
alert(error);
}else if(data=='plzcomment'){
alert("please enter comment");
}else{
$(".feed-comments-"+id).append(data);
}
$('#comm_area-'+id).val('');
});
return false;
}
note: i submit form by enter button click