jQuery:而ajax请求块元素 [英] jQuery: While ajax request block element
问题描述
所以我在JS中具有此功能,发送请求以向数据库中插入新的状态消息.
So i have this function in JS, sending a request to insert a new Status message to the database.
function DoStatusInsert(){
var wrapperId = '#statusResponseNow';
$.ajax({
type: "POST",
url: "misc/insertStatus.php",
data: {
value: 'y',
uID : $('#uID').val(),
message : $('#message').val()
},
success: function(msg){
$('#message').val("");
$('#statusResponse').toggle();
$(wrapperId).prepend(msg);
$(wrapperId).children().first().fadeIn('slow');
}
});
}
采用以下形式:
<input name="message" type="text" id="message" value="" size="60">
<input type="hidden" name="uID" id="uID" value="<?php echo $v["id"]; ?>">
<input name="submit" type="submit" id="submit" value="Spara">
<div id="statusResponseNow"></div>
现在,我希望执行诸如将提交"按钮或消息字段阻止为只读"的操作,直到收到响应/成功为止,因此您没有机会喜欢多次按提交",因此它会多次插入..(我知道您可以在DB中的double's之后制作一个php进行检查)
Now I wish to do something like blocking the submit button or the message field to "read-only" until you receive response / success, so you don't have the opportunity to like press submit alot of times so it inserts alot.. (i know you could make a php for checking after double´s in DB)
所以:当您单击提交"时,它将使消息字段和/或提交"按钮均为只读
So: when you click on submit then it makes either message field and/or submit button to read only
我应该怎么做?
推荐答案
function DoStatusInsert(){
$('#IdOfYourSaveButton').attr('disabled', 'disabled');
var wrapperId = '#statusResponseNow';
$.ajax({
type: "POST",
url: "misc/insertStatus.php",
data: {
value: 'y',
uID : $('#uID').val(),
message : $('#message').val(),
success: function(msg){
$('#IdOfYourSavebutton').removeAttr('disabled');
$('#message').val("");
$('#statusResponse').toggle();
$(wrapperId).prepend(msg);
$(wrapperId).children().first().fadeIn('slow');
}
});
}
启用并禁用该按钮.很好很容易:)
enabled and disable the button. nice and easy :)
这篇关于jQuery:而ajax请求块元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!