简体   繁体   中英

How do I re-initialize jQuery file upload data array?

I'm using jQuery file upload in my web site for users to upload there Photos. Following is my JS code calling file upload plugin, (Please have a look at code comments as well...)

$('#fileupload').click(function(){  
$('#fileupload').fileupload({
        dataType: 'json',
        url: 'productpage/uploadphoto?design='+ globalVars.selectedDesignId,
        prependFiles: true,
        start: function(){
            $("#pp-photo-area").show();
        },
        done: function (e, data) {
            console.log(data); // Only gives me new file data
            loadPhotoStudio(data); //Data is sent to another function
        }           
    }); 
});

And each time a user uploads a file it get added to the data array with the old file data in it, which I dont want to happen. I want it to replace the previous data array with the new one. So that I can use this data in loadPhotoStudio() function.

var loadPhotoStudio = function(data) {
  $('#test').click(function(){
        $.each(data.result.files, function (index, file) {
            console.log(file.name) //This gives me all files uploaded
        });
    });   
}

How do I refresh data array before each upload?

try to add this to the 'done' queue:

reset_field($('#fileupload'));

Corresponding to this function

function reset_field (e) {
        e.wrap('<form>').parent('form').trigger('reset');
        e.unwrap();
}   

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM