Form form

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?

Mar.18,2021

1. Different formdata corresponds to form tag
2, formdata2 can
3, not necessarily file can be obtained dynamically and then append can be entered into formdata object
4, not necessarily, if you want not to pass append, you need

.

because formdata corresponds to the form under the form tag and must contain the name attribute before it can be formdata to

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e478db-6525c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e478db-6525c.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?