如何防止通过POST在下一条路线上重新发送表单?

时间:2018-12-01 20:46:00

标签: javascript node.js axios

我的表单正在正常运行,并且正在将其发送到下一条路线...

问题是,在到达下一条路线并单击F5按钮时,会出现消息“表格转发” ,但是我需要防止这种情况。

在到达下一条路线时,提交的表单应“死亡”。

注意:很遗憾,它必须使用POST。

  /** @description MANIPULA TODA A LÓGICA DO FORMULÁRIO */
    create(){
        this.verifyInputsValue();

        // ESCUTA O EVENTO 'SUBMIT' DO FORMULÁRIO
        this.form.addEventListener('submit', event => {
            event.preventDefault();
            this.form.setAttribute('class', 'was-validated');

            this.clearLoginButton();
            this.createLoginLoading();

            // VERIFICA SE O FORMULÁRIO ESTÁ VÁLIDO
            if(!this.form.checkValidity()){
                event.stopImmediatePropagation();

                this.clearLoginButton()
                this.createLoginText();
            } else {
                const httpRequest = new HTTP();
                httpRequest.postUserAuthentication(this.usernameValue, this.passwordValue).then((response) => {
                    this.createInputToken(response.data.token);
                    this.form.submit();
                    event.preventDefault();
                    event.stopImmediatePropagation();
                }).catch(() => {
                    event.stopImmediatePropagation();

                    this.clearLoginButton();
                    this.createLoginText();

                    super.clearInvalidFeedback(this.backendMessage);
                    this.createInvalidFeedback();
                });
            }
        });
    }

enter image description here

0 个答案:

没有答案