I am using jQuery v2.1.4, I have the following function which for each object in evt.data.files
(the number of element in the array will vary) needs to make a request to a server.
The problem I am facing with this script is that for each element in evt.data.files
an asynchronous request is made, instead I need:
- execute each request in
sequence
(if possible with jQuery) - call a single method when
all
the request are successfully returned.
Could you please suggest me a solution with an example? Thanks.
options.onInit = function (finder) {
finder.on('files:choose', function (evt) {
// files is an array of n object
evt.data.files.forEach(function (file) {
// req is an jquery deferred object
var req = finder.request('command:send', {
name: 'ImageInfo',
folder: file.get('folder'),
params: { fileName: file.get('name') }
}).done(function (response) {
if (response.error) {
return;
}
});
});
});
}.bind(this);