问题
I am using GAE for an app that has various submit href buttons, and use javascript to submit.
I am having a real tough time trying to figure out how to prevent multiple submits or doubl-clicking. I have tried various methods to disable or remove the href with javascript.
But I am thinking if there is maybe a method to prevent this in the backend.
What methods would you recommend I use?
回答1:
Preventing it on the server side is not trivial - a second call may hit a different instance. So you need to deal with sessions. The code will get complex quickly.
I would recommend disabling the button before a call and reenabling it upon a response.
回答2:
You can use a javascript to disable all submit buttons on your page when a form is submitted. Maybe something like this:
document.forms[0].addEventListener('submit', function() {
var btns = document.querySelectorAll('input[type="submit"]');
for (var i = 0; i < btns.length; i++) {
btns[i].disabled = 'disabled';
}
});
If you need to also disable other elements you can modify the querySelector.
来源:https://stackoverflow.com/questions/23739630/prevent-double-submits