How to prevent form resubmission when page is refreshed (F5 / CTRL+R)

后端 未结 23 1303
醉话见心
醉话见心 2020-11-22 00:46

I have a simple form that submits text to my SQL table. The problem is that after the user submits the text, they can refresh the page and the data gets submitted again with

23条回答
  •  悲哀的现实
    2020-11-22 01:42

    Basically, you need to redirect out of that page but it still can make a problem while your internet slow (Redirect header from serverside)

    Example of basic scenario :

    Click on submit button twice

    Way to solve

    • Client side

      • Disable submit button once client click on it
      • If you using Jquery : Jquery.one
      • PRG Pattern
    • Server side

      • Using differentiate based hashing timestamp / timestamp when request was sent.
      • Userequest tokens. When the main loads up assign a temporary request tocken which if repeated is ignored.

提交回复
热议问题