#jQuery fileupload for dynamically added input field


Updated September 2, 2015 ● 7,860 views

jQuery fileupload from Blueimp is one of the good file upload jQuery Ajax classes. I used this class in the development of this website.

To make it work for dynamically added input field use the jQuery live() function. This attach an event handler for all elements which match the current selector, now and in the future.

Example:

$('#fileupload').live('click', function(e) {
    $('#fileupload').fileupload({
        url: '',
        type:'post',dataType: 'json',autoUpload: false,
        formData: {},
        add: function(e, data, textStatus){
            .success(function (result, textStatus, jqXHR) {})
            .error(function (jqXHR, textStatus, errorThrown) {})
            .complete(function (result, textStatus, jqXHR) {});
        },       
        progress: function (e, data, jqXHR) {
        },          
        done: function (e, data) {
        },
    })
});

3 Comments

Sort by Best Controversial New
 
2

Thank you so much. I have spent a lot of time trying to get the fileupload to work with dynamic vars until I found this post.

cami · 10 years ago
permalink · reply (0)
1

Fantastic! Thank you very much!

Prakash1 · 11 years ago
permalink · reply (0)
0

Thanks for this tip! I've been wondering why the hell the jQuery fileupload wasn't working.

Ronn · 11 years ago
permalink · reply (0)

This website uses cookies. By continuing to use this site, you are accepting our Privacy Policy and Terms of Service.