0
Friends, I am 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 dd() command and I realized that when I print "idfolder" I have the following scenario: sometimes the ID comes correctly and sometimes nothing comes, just an empty string.
I believe it is an asynchronous request and I am taking data from another component of jQuery and this is giving me problems.
If I print per console.log(jQuery("#list-id-client").html()) always returns something, unlike ajax request.
Is there anything that can be done? I need to get this customer ID by jQuery...
Thank you
Add the parameter: 'async:false' in the request, and see if the problem remains.
– AnthraxisBR
If I put async:false, the plugin crashes. = ( Have some other idea?
– Gabriel Augusto
The "#list-id-client" element is an input ?
– AnthraxisBR
It’s actually a span that contains the number I need. This span is filled with the number I need before calling this method I’m using. If I add a beforeSend: {console.log("#list-id-client")} I can clearly see that what I need is there, but I’m not able to manipulate beforeSend so I can ensure that this data goes to the route I want.
– Gabriel Augusto
Got it, do you submit this form as ? have some jQuery event on some button or did you have it directly identified on Submit ? I think the mistake is the timing really
– AnthraxisBR
Actually the error was synchronized. I looked at the documentation of the plugin itself, there is a method called . bind that solved the problem. Thanks for your help, buddy!
– Gabriel Augusto
Nice, answer your own question with the solution, can help more people!
– AnthraxisBR