问题:
I would like to upload a file asynchronously with jQuery. 我想用jQuery异步上传文件。 This is my HTML: 这是个人HTML: html
<span>File</span> <input type="file" id="file" name="file" size="10"/> <input id="uploadbutton" type="button" value="Upload"/>
And here my jQuery code: 这是个人jQuery代码: ajax
$(document).ready(function () { $("#uploadbutton").click(function () { var filename = $("#file").val(); $.ajax({ type: "POST", url: "addFile.do", enctype: 'multipart/form-data', data: { file: filename }, success: function () { alert("Data Uploaded: "); } }); }); });
Instead of the file being uploaded, I am only getting the filename. 我只获取文件名,而不是上传文件。 What can I do to fix this problem? 我该怎么作才能解决此问题? 异步
解决方案:
参考一: https://stackoom.com/question/hEz/如何异步上传文件参考二: https://oldbug.net/q/hEz/How-can-I-upload-files-asynchronously