簡體   English   中英

將文件名獲取到myXhr.upload

[英]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;

https://jsfiddle.net/a264am6m/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM