Use jquery component inside a formData (fileupload)

0

Friends, I'm using the jquery fileupload plugin and using the following callback:

jQuery("#fileupload").fileupload({
    url: '/painel/uploads',
    dataType: 'json',
    formData: {_token: jQuery("#fileupload").data('token'), idpasta: jQuery("#list-id-client").html()},
    done: function (e, data) {

    },
    progressall: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css(
            'width',
            progress + '%'
        );
    }
});

I am printing this request with the PHP command dd () and I realized that when I print "idpasta" I have the following scenario: sometimes the ID comes correctly and sometimes it comes with nothing, just an empty string.

I think it's an asynchronous request and I'm getting data from another jQuery component and this is giving me problems.

Is there anything that can be done? I need to get this client ID by jQuery ...

Thank you

    
asked by anonymous 31.10.2017 / 03:34

1 answer

1

I found the answer, it was sync error itself.

The plugin itself provides a bind method. I looked at the documentation and was able to implement the following, which solved the problem:

jQuery("#fileupload")
    .bind('fileuploadsubmit', function(e, data) {
        var idPasta = $("#idPasta").val();
        data.formData = {_token: jQuery("#fileupload").data('token'), idpasta: idPasta};
    })

    .fileupload({
    url: '/painel/uploads',
    dataType: 'json',

    done: function (e, data) {

    },
    progressall: function (e, data) {
        var progress = parseInt(data.loaded / data.total * 100, 10);
        $('#progress .progress-bar').css(
            'width',
            progress + '%'
        );
    }
});

Thank you!

    
31.10.2017 / 17:03