How do I stop the Back and Refresh buttons from resubmitting my form?

后端 未结 13 1324
时光说笑
时光说笑 2020-11-27 15:16

I am doing web development.

I have a page to do with credit card, which when user click \"refresh\" or \"Back\", the transaction will be performed one more time, wh

13条回答
  •  天涯浪人
    2020-11-27 15:42

    I didn't see this here so here it is.

    1. Put a unique token in the form.
    2. The submit button triggers an xmlhttp(ajax) request to the server to create a session variable named after the token with a stored value of 1.
    3. The ajax request submits the form after receiving a positive state change.
    4. The form processing script checks for the session variable withe the stored value of 1.
    5. The script removes the session variable and processes the form.

    If the session variable is not found, the form will not be processed. Since the variable is removed as soon as its found, the form can only be run by pressing the submit button. Refresh and back will not submit the form. This will work without the use of a redirect.

提交回复
热议问题