upload pictures
< input id= "file" type= "file" accept= "image/*" multiple= "name=" file ">
< script >
let formData = new FormData();
let element = document.getElementById("file");
element.addEventListener("change", function () {
//
console.log(this);
//
console.log(this.files);
formData.append("file",this.files);
console.log(formData);
AJAX
});
< / script >
or
< form id= "upload" >
<input id="file" type="file" accept="image/*" multiple="" name="file">
< / form >
< script >
let element = document.getElementById("file");
element.addEventListener("change", function () {
let formData1 = new FormData(document.getElementById("file"));
let formData2 = new FormData(document.getElementById("upload"));
console.log(formData1);
console.log(formData2);
AJAX
});
< / script >
Q:
is formData1 the same as formData2?
can both of the above methods upload pictures?
does the input for uploading pictures have to be put in form? Does the
form have to be placed in form?