我现在在Play Framework(2.2.3)中进行一些练习。我想上传一个文件,并使用jquery和ajax将其保存在单击按钮上的播放框架服务器路径中。所以,如果我知道jQuery中的文件上传路径,我可以在我的应用程序中使用它。请告诉我如何实现这一目标?我做了类似下面的事情,因为我不知道我的文件上传到哪里,它应该存储在我的播放服务器中。
HTML:
<span>File</span>
<input type="file" id="file" name="file" size="10"/>
<input id="uploadbutton" type="button" value="Upload"/>
的jquery + AJAX:
$(document).ready(function () {
$("#uploadbutton").click(function () {
//var filename = $("#file").val();
var filename = $("#file").val().replace(/C:\\fakepath\\/i, '');
console.log("filename: "+filename);//uploaded file names
$.ajax({
type: "POST",
url: "/upload",
enctype: 'multipart/form-data',
data: {
file: filename
},
success: function () {
alert("File is Uploaded: ");// where it is uploaded ?
},
error: function (xhr, ajaxOptions, thrownError) {
console.log(xhr.status);
console.log(xhr.responseText);
}
});
});
});