Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Let's say I have this element on the page:(假设我在页面上有此元素:)

<input id="image-file" type="file" /> This will create a button that allows the users of the web page to select a file via an OS "File open..." dialog in the browser.(这将创建一个按钮,允许网页用户通过浏览器中的OS“文件打开...”对话框选择文件。) Let's say the user clicks said button, selects a file in the dialog, then clicks the "Ok" button to close the dialog.(假设用户单击该按钮,在对话框中选择一个文件,然后单击“确定”按钮以关闭对话框。) The selected file name is now stored in:(所选文件名现在存储在:) document.getElementById("image-file").value Now, let's say that the server handles multi-part POSTs at the URL "/upload/image".(现在,假设服务器在URL“ / upload / image”处处理多部分POST。) How do I send the file to "/upload/image"?(如何将文件发送到“ / upload / image”?) Also, how do I listen for notification that the file is finished uploading?(另外,如何侦听文件上传完成的通知?)   ask by YummyBánhMì translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
125 views
Welcome To Ask or Share your Answers For Others

1 Answer

Unless you're trying to upload the file using ajax, just submit the form to /upload/image .(除非您尝试使用ajax上传文件,否则只需将表单提交/upload/image 。)

<form enctype="multipart/form-data" action="/upload/image" method="post"> <input id="image-file" type="file" /> </form> If you do want to upload the image in the background (eg without submitting the whole form), you can use ajax:(如果您确实想在后台上传图像(例如,无需提交整个表单),则可以使用ajax:) Asynchronous file upload (AJAX file upload) using jsp and javascript(使用jsp和javascript的异步文件上传(AJAX文件上传)) jQuery Ajax File Upload(jQuery Ajax文件上传) Ajax using file upload(使用文件上传的Ajax)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...