function commentpost(){
var allow = true;
var game = "<?php echo $game ?>";
var name = $("input#name").val();
var comment = $("textarea#comment").val();
var date = currentdate();
var dataString = "postdate=" + date + "&game=" + game + "&name=" + name + "&comment=" + comment;
if(name && comment && allow){
$.ajax({
type: "POST",
url: "../php/addcomment.php",
data: dataString,
success: function(){
updatecomments();
//important part here V
allow = false;
setTimeout(function(){
allow = true;
// alert(allow);
}, 5000);
// alert(allow);
//important part here ^
}
});
}
//important part here V
else if ((!name || !comment) && allow){
alert("Please fill out both the Name and Comment fields");
}
else if (!allow){
alert("Commenting has been limited to 5 seconds in between to pevent spamming.");
}
//important part here ^
}
我正在创建的网站上有一个小的基本评论脚本。这一切都很好,但我试图防止提交按钮被垃圾邮件。这似乎对我来说应该有效,但由于某种原因它不是,我认为由于我使用“允许”的方式。