I would like to upload a file asynchronously with jQuery.(我想用jQuery异步上传文件。)
This is my 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代码:)
$(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?(我该怎么做才能解决此问题?)
ask by Sergio del Amo translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…