FormData doesn't include the button Javascript

后端 未结 2 826
半阙折子戏
半阙折子戏 2020-12-20 19:04

I\'m having a problem with FormData, it was working a couple days ago but now it doesn\'t work, it submits all the inputs except the submit button. Here\'s my l

2条回答
  •  执笔经年
    2020-12-20 19:38

    Because you're not actually using the default submit (instead you're doing ajax), you need to add the clicked button yourself. One easy way to do this is to add a hidden input to your form with the name you want the button to have, and then have all the buttons in the form use this click handler:

    function clickHandler() {
        this.form.theHiddenInput.value = this.value;
    }
    

    That way, if a button was used to submit the form, the button's handler sets the value of the hidden input prior to the submit.

提交回复
热议问题