在easyui创建新用户时如何在将请求发送到php以将其插入数据库时禁用多次单击保存按钮
function saveUser() {
$('#fm').form('submit', {
url: url,
onSubmit: function() {
return $(this).form('validate');
},
success: function(result) {
if (result === 'exists') {
$.messager.alert('Alert', 'Name already exists!\nPlease enter different Name', 'info');
$('#fm').form('clear');
} else {
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}
直到答案没有从php文件到达,我不想要发送另一个请求。
答案 0 :(得分:1)
您可以在点击后立即停用提交按钮,
请检查以下代码,希望它可以帮助您:
function saveUser() {
$('#fm').form('submit', {
url: url,
onSubmit: function() {
//Code to Disable the submit button comes here.
$("#SubmitButton").attr('disabled',true);//Assuming SubmitButton is the ID of the button.
return $(this).form('validate');
},
success: function(result) {
if (result === 'exists') {
$.messager.alert('Alert', 'Name already exists!\nPlease enter different Name', 'info');
$('#fm').form('clear');
} else {
//If you want to allow the user to click on the Submit button now you can enable here like this :
$("#SubmitButton").attr('disabled',false);
$('#dlg').dialog('close'); // close the dialog
$('#dg').datagrid('reload'); // reload the user data
}
}
});
}