#jQuery fileupload for dynamically added input field


Updated September 2, 2015 ‚óŹ 6,928 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 · 4 years ago
permalink · reply (0)
1

Fantastic! Thank you very much!

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

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

Ronn · 5 years ago
permalink · reply (0)



Our Terms of Use and Privacy Policy have changed.
By continuing to use this site, you are agreeing to the new Privacy Policy and Terms of Use.