我写了一个基本的评论系统,它是一个简单的写入数据库表单,它也使用ajax。停止发送数据的ajax请求,直到收到响应为止?
问题是,如果我输入我的消息,然后垃圾邮件发送/回车键似乎堆积起来,然后一切都写入数据库多次。
我的AJAX是像这样:
$(document).ready(function(){
$(document).on('submit', '.addcomment', function() {
var $targetForm = $(this);
$.ajax({
type: "POST",
url: "process/addcomment.php",
data: $targetForm.serialize(),
dataType: "json",
success: function(response){
if (response.databaseSuccess == true) {
$("#container").load("#container");
$targetForm.find('#addcommentbutton').attr("disabled", true);
}
else {
$ckEditor.after('
}
}
});
return false;
});
});
提交按钮也被禁用,但形式仍然可以通过与提交按钮的大量垃圾邮件进入键盘按钮,甚至还可以进入(这是应该被禁用)
有没有办法使用jquery 100%禁用此表单,直到收到成功的JSON消息?
更多代码只是让我知道!
2014-02-10
Lovelock
+0
你可以使用jQuery的提交事件,并检查是否从你的Ajax一个变量是设置为“true”,如果它已经设置了submit();经过。 –
+2
您正在禁用提交按钮的方式太晚了。 –