How can I prevent a double submit with jQuery or Javascript?

前端 未结 10 1309
终归单人心
终归单人心 2020-12-08 22:44

I keep getting duplicate entries in my database because of impatient users clicking the submit button multiple times.

I googled and googled and found a few scripts,

10条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 22:51

    One technique I've seen used is to assign a unique ID to every form that's opened, and only accept one submission per form based on the ID.

    It also means you can check how many times people aren't bothering to submit at all, and you can check if the submission genuinely came from your form by checking if it's got an ID that your server created.

    I know you asked for a javascript solution, but personally I'd do both if I needed the robustness.

提交回复
热议问题