This article describes how to submit a form and upload an image using the FormData object in php + html5. The example shows how to use the FormData object, which is of great practical value, for more information about how to use the FormData object to submit a form and upload an image, see the example in this article. Share it with you for your reference. The specific analysis is as follows:
FormData object. you can combine the name and value of all form elements in form into a queryString and submit it to the background. When Ajax is used for submission, using the FormData object can reduce the amount of work required to splice queryString.
Use FormData object
1. create a FormData empty object and use the append method to add key/value
The code is as follows:
Var formdata = new FormData ();
Formdata. append ('name', 'fdipzone ');
Formdata. append ('gender', 'male ');
2. get the form object and pass it as a parameter to the FormData object
The code is as follows:
The code is as follows:
Var form = document. getElementById ('form1 ');
Var formdata = new FormData (form );
Use FormData to submit a form and upload a file:
The code is as follows:
FormData Demo