最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - data.context is empty on fileuploadprogress event of jQuery File Uploader - Stack Overflow

programmeradmin1浏览0评论

I am experiencing issues with the jQuery File Uploader (blueimp):

My implementation is fully customized. I use image previews and validation.

My problem is that even though i am defining data.context in my fileuploadadd event, it es in empty when fileuploadprogress is fired.

$('fileinput-element').fileupload({
    url: '/__module/uploadModule/receive',
    type: 'post',
    acceptFileTypes: acceptedFileRegEx,
    dataType: 'json',
    'dropZone': $(dropZone),
    paramName: 'files',
    autoUpload: false,
}).on('fileuploadadd', function (e, data) {

    $.each(data.files, function (index, file) {

        // NOTE: This function call returns a clone of an element that i use as template for upload list items. Works fine.
        var ponent=uploadModule.getDynamicComponent('listItemContainer');

        // Filling the template (code omitted due to better readabilty)

        // Appending the ponent to my #uploadList and assigning that to data.context
        data.context = ponent.appendTo('#uploadList');

    });

    // For manual submittion later on, i fill an array with the data objects from each event call
    dataList.push(data);

}).on('fileuploadprocessalways', function(e,data){

    var index = data.index,
        file = data.files[index],
        node = $(data.context.children()[index]);

    // Further code ommitted due to readability. Here i apply file.preview and (potential) file.error to my list item that is now stored in the variable node. This works fine. My list renders perfectly well.

}).on('fileuploadprogress', function(e, data){

    // PROBLEM: data.context is EMPTY ! Why???
    console.log(data.context);

});

And this is how i submit everything upon clicking a start upload button:

$(dataList).each(function(){
    this.submit();
});

// This works well - the uploads are being submitted and sent to the server.

I have done extensive solution searching, testing, trial & error, debugging for 1.5 days now. I just can't wrap my head around this.

What am i doing wrong?

Please note: If i do a data.submit() right inside the add event callback, then data.context is filled correctly when the progress event fires, but i am no longer left with the option of manually launching the entire upload queue.

I am experiencing issues with the jQuery File Uploader (blueimp):

My implementation is fully customized. I use image previews and validation.

My problem is that even though i am defining data.context in my fileuploadadd event, it es in empty when fileuploadprogress is fired.

$('fileinput-element').fileupload({
    url: '/__module/uploadModule/receive',
    type: 'post',
    acceptFileTypes: acceptedFileRegEx,
    dataType: 'json',
    'dropZone': $(dropZone),
    paramName: 'files',
    autoUpload: false,
}).on('fileuploadadd', function (e, data) {

    $.each(data.files, function (index, file) {

        // NOTE: This function call returns a clone of an element that i use as template for upload list items. Works fine.
        var ponent=uploadModule.getDynamicComponent('listItemContainer');

        // Filling the template (code omitted due to better readabilty)

        // Appending the ponent to my #uploadList and assigning that to data.context
        data.context = ponent.appendTo('#uploadList');

    });

    // For manual submittion later on, i fill an array with the data objects from each event call
    dataList.push(data);

}).on('fileuploadprocessalways', function(e,data){

    var index = data.index,
        file = data.files[index],
        node = $(data.context.children()[index]);

    // Further code ommitted due to readability. Here i apply file.preview and (potential) file.error to my list item that is now stored in the variable node. This works fine. My list renders perfectly well.

}).on('fileuploadprogress', function(e, data){

    // PROBLEM: data.context is EMPTY ! Why???
    console.log(data.context);

});

And this is how i submit everything upon clicking a start upload button:

$(dataList).each(function(){
    this.submit();
});

// This works well - the uploads are being submitted and sent to the server.

I have done extensive solution searching, testing, trial & error, debugging for 1.5 days now. I just can't wrap my head around this.

What am i doing wrong?

Please note: If i do a data.submit() right inside the add event callback, then data.context is filled correctly when the progress event fires, but i am no longer left with the option of manually launching the entire upload queue.

Share Improve this question edited Oct 7, 2013 at 15:07 SQRCAT asked Oct 7, 2013 at 14:55 SQRCATSQRCAT 5,8409 gold badges47 silver badges78 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 11

The solution to this problem was quite a surprise:

My load order for the fileupload ponent and plugins was:

jquery
jquery-ui (for the widget
load-image.js
iframe-transport.js
fileupload.js
fileupload-process.js
fileupload-image.js
fileupload-validate.js
fileupload-ui.js

And the last one (fileupload-ui.js) was the pitfall. I thought i had to include it for my implementation of the uploader, but i didn't. Seems i misunderstood what it was for.

The moment i removed it, my script / implementation started working, data.context now gets populated correctly.

发布评论

评论列表(0)

  1. 暂无评论