我在jsp中输入以下代码,我们输入主题和消息,然后单击导致表单提交的按钮,当我们通过单击F5进行页面刷新时,它会导致多个表单提交。
我添加了以下行$('form')。preventDoubleSubmission();和我的jsp中对应的函数但它仍然无法正常工作。请协助。
function validateXYZ() {
var frm = document.forms["update-xyz"];
frm.actionType.value=message;
if (message == "submit_new") {
if (frm.subject.value == "" || frm.content.value == "") {
alert ("Please fill in Subj and Msg");
return false;
}
}
$('form').preventDoubleSubmission();
frm.submit();
}
//jQuery plugin to prevent double submission of forms
/*jQuery.fn.preventDoubleSubmission = function() {
$(this).on('submit',function(e){
var $form = $(this);
if ($form.data('submitted') === true) {
// Previously submitted - don't submit again
e.preventDefault();
} else {
// Mark it so that the next submit can be ignored
$form.data('submitted', true);
}
});
谢谢, Praseel。