Php + html5 uses the FormData object to submit a form and upload an image ,. Php + html5 uses the FormData object to submit a form and upload an image. This article describes how php + html5 uses the FormData object to submit a form and upload an image. I would like to share with you how to submit a form and upload images using the FormData object in php + html5,
This example describes how to submit a form and upload an image using the FormData object in php + html5. 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