dams
dams

Reputation: 329

jquery deferred ajax calls execution

I'm trying to load several scripts at runtime using Jquery, and then fire an event once they are loaded. The code has to handle an arbitrary number of scripts, so I use

$.when.apply

The problem is that the event is not triggered at the right time. Here is my jsfiddle:

http://jsfiddle.net/dams_666/kWP36/93/

for (var i = 0; i < myScripts.length; i++) {
    deferred.push(getScript(myScripts[i]));
}

$.when.apply($, deferred).then(finished());

Thanks in advance for your help

Upvotes: 2

Views: 398

Answers (1)

Giovanni Filardo
Giovanni Filardo

Reputation: 1022

You are invoking the finished function, instead of passing it as an argument. To pass it, use

$.when.apply($, deferred).then(finished);

Instead of

$.when.apply($, deferred).then(finished());

Upvotes: 3

Related Questions