How to upload a file using javascript?
问题 I want to create a uploader with js. Can anyone help me how to upload a file using javascript? 回答1: You can use html5 file type like this: <input type="file" id="myFile"> You file will be in value: var myUploadedFile = document.getElementById("myFile").files[0]; For more information see https://www.w3schools.com/jsref/dom_obj_fileupload.asp and see example here: https://www.script-tutorials.com/pure-html5-file-upload/ 回答2: You can upload files with XMLHttpRequest and FormData . The example