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.

5
  • 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? Commented Jul 18, 2013 at 9:09
  • can you share the loop also Commented Jul 18, 2013 at 9:13
  • @roasted the fact that you don't know the answer, doesn't yet make the question vague;) Commented Jul 18, 2013 at 9:37
  • 1
    @user1514042 I don't know what? How to use a closure? Actually i don't understand this part of your question: <<I need to inject some extra data into $.getScript call, so it'll be availabe in ready handler>> 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... Commented Jul 18, 2013 at 9:54
  • I'm sorry if it wasn't clear:) Closure is just means for achieving what I was looking for! Commented Jul 18, 2013 at 10:59

1 Answer 1

0

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);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.