How can I get form data with JavaScript/jQuery?

前端 未结 28 1931
不知归路
不知归路 2020-11-22 12:39

Is there a simple, one-line way to get the data of a form as it would be if it was to be submitted in the classic HTML-only way?

For example:



        
28条回答
  •  囚心锁ツ
    2020-11-22 13:08

    You can also use the FormData Objects; The FormData object lets you compile a set of key/value pairs to send using XMLHttpRequest. Its primarily intended for use in sending form data, but can be used independently from forms in order to transmit keyed data.

            var formElement = document.getElementById("myform_id");
            var formData = new FormData(formElement);
            console.log(formData);
    

提交回复
热议问题