我正在使用 Jquery Modal Dialog 将一些数据提交到服务器端,然后保存到数据库中;这里我的模态对话框代码是:
function loadUserDialog(tag, event, target, id) {
event.preventDefault();
$.validator.unobtrusive.parse('#frmModalPopup');
var $loading = $('<img src="@Url.Content("~/Content/images/ajaxLoading.gif")" alt="loading" class="ui-loading-icon" style="margin: 150px 150px;">');
var $url = $(tag).attr('href');
var $title = $(tag).attr('title');
var $dialog = $('<div></div>');
$dialog.empty();
$dialog
.append($loading)
.load($url)
.dialog({
autoOpen: false
, title: $title
, width: 500
, modal: true
, minHeight: 400
, show: 'fade'
, hide: 'fade'
});
$dialog.dialog("option", "buttons", {
"Submit": function () {
var dlg = $(this);
if (IsValidUserName() && $('#frmModalPopup').validate().form()) {
$.ajax({
url: $url,
type: 'POST',
data: $(target).serialize(),
success: function (response) {
var cid = $(response).attr('id');
if (cid != null && cid != undefined) {
$(response).fadeIn('slow').appendTo(id);
$(window).scrollTop($('#' + cid).offset().top);
}
dlg.dialog('close');
dlg.empty();
},
error: function (xhr) {
alertMessage("EmailId is already in use!");
$.validator.unobtrusive.parse('#frmModalPopup');
}
});
}
},
"Cancel": function () {
$(this).dialog('close');
$(this).empty();
}
});
$dialog.dialog('open');
};
但是当我一次多次点击提交按钮时(不止一次),表单被提交了不止一次,我得到了重复的数据提交信息。那么您能否告诉我如何禁用双击或多次单击按钮提交。