Question

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

Était-ce utile?

La solution

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());
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top