0

I need to inject some extra data into $.getScript call, so it'll be availabe in ready handler, how do I do that?

// since it's called in a loop I need pass context into read handler
$.getScript(path, function (e2) {

};

in regular event handlers I can do do by passing the data as a second parameter and get it by e.data.* from within the event handler:

element.on("event", { extra: "data" }, function(e) { console.log(e.data.extra); });

which doesn't seem to work with $.getScript.

user1514042
  • 1,899
  • 7
  • 31
  • 57
  • Your question is vague. Document ready handler won't wait for async scripts to be loaded, window onload will do. What loop are you talking about? $.getScript method sig doesn't accept any extra params, you could still pass it inside the URI i think but then need to be processed server side. I'm not sure it is possible using $.getScript(). Could you provide a more complete example of what you are looking for? – A. Wolff Jul 18 '13 at 09:09
  • can you share the loop also – Arun P Johny Jul 18 '13 at 09:13
  • @roasted the fact that you don't know the answer, doesn't yet make the question vague;) – user1514042 Jul 18 '13 at 09:37
  • 1
    @user1514042 I don't know what? How to use a closure? Actually i don't understand this part of your question: <> The answer gives by Arun P Johny as nothing to do with it, it has to do with the callback function of getScript() method. So ya, your question was/is vague... – A. Wolff Jul 18 '13 at 09:54
  • I'm sorry if it wasn't clear:) Closure is just means for achieving what I was looking for! – user1514042 Jul 18 '13 at 10:59

1 Answers1

1

The .getSCript() does not provide that functionality, but I think you can make use of closure here

Ex:

for(var i = 0; i < x; i++){
    (function(idx){
        $.getScript(path, function (e2) {
            console.log(idx);
        });
    })(i);
}
Arun P Johny
  • 384,651
  • 66
  • 527
  • 531