Use FormData to upload files and images,
About FormData
- XMLHttpRequest Level 2 adds a new interface ---- FormData
- The FormData object can be used to simulate a series of form controls using some key-value pairs in js. The send () method of XMLHttpRequest can be used to submit forms asynchronously.
- Compared with normal ajax, FormData can be used to upload binary files asynchronously.
FormData object
-
- FormData object, which can combine the name and value of all form elements 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.
- QueryString is the query string, and the http query string is in the url? Specify the value following
- When the form on the page sends request data to the page in the GET mode (if the data contains insecure characters, the browser first converts the data to hexadecimal characters before transmission, if a space is converted to % 20), the web server puts the request data in an environment variable named QUERY_STRING. The Request. QueryString method extracts the corresponding value from this environment variable and restores the value to a hexadecimal character.
Use FormData to upload files and Images