![](/img/trans.png)
[英]Ajax upload — how to get the FormData filename vs the raw file filename
[英]Get filename into myXhr.upload
我正在像這樣用ajax上傳圖片:
$.ajax({
// Your server script to process the upload
url: 'upload.php',
type: 'POST',
// Form data
data: new FormData($('form')[0]),
// Tell jQuery not to process data or worry about content-type
// You *must* include these options!
cache: false,
contentType: false,
processData: false,
// Custom XMLHttpRequest
xhr: function() {
var myXhr = $.ajaxSettings.xhr();
if (myXhr.upload) {
// For handling the progress of the upload
myXhr.upload.addEventListener('progress', function(e) {
console.log(myXhr);
if (e.lengthComputable) {
$('progress').attr({
value: e.loaded,
max: e.total
});
}
} , false);
}
return myXhr;
}
});
我想知道當前上傳文件的名稱,以及他在“ myXhr.upload.addEventListener('progress',function(e){“ function)中的輸入名稱。
有可能在這里知道嗎?
您可以在progress
事件中找到輸入:
var inputFile = $('form').find("input[type=file]");
var fileName = inputFile[0].files[0].name;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.