<a href="//m.sbmmt.com/wiki/125.html" target="_blank">For</a>mData
Object , You can use a series of key-value pairs to simulate a complete form, and then use <a href="//m.sbmmt.com/wiki/1527.html" target="_blank">XML</a>HttpRequest
to send this "form"
inMozilla Developer. The website uses the FormData object and has detailed instructions for using the FormData
object.
But the upload file part only has the underlying XMLHttpRequest
object to send for upload. request, then how to upload through Ajax<a href="//m.sbmmt.com/wiki/1495.html" target="_blank"> of </a>
jQuery
This article will introduce how to use FormData## through
jQuery #Object upload file.
FormData object. ? Use
FormData object to add fields to upload files
HTML code
<p id="uploadForm"> <input id="file" type="file"/> <button id="upload" type="button">upload</button> </p>
tag here, There is no
enctype="multipart/form-data" attribute either.
javascript codevar formData = new FormData(); formData.append('file', $('#file')[0].files[0]); $.ajax({ url: '/upload', type: 'POST', cache: false, data: formData, processData: false, contentType: false }).done(function(res) { }).fail(function(res) {});
There are a few differences here: The second parameter of
should be File object, i.e. $('#file')[0].files[0]
.
also needs to be set to ‘false’.
You can see an <input type="file from the code
$('#file')[0].files[0] ">
tag can upload multiple files,
multiple= in <input type="file">
"multiple"
Starting from
Servlet
3.0
, you can use request.getPart()
or request.getPars()
Two interfaces
get uploaded files.
The above is the detailed content of FormData object uploads files. For more information, please follow other related articles on the PHP Chinese website!