0

I am trying to load a script within a function that depends on a variable of that function. Basically, the code is like this

head.js("somescript.js", function() {

   var dependentVar = //stuff;

    //insert script here which depends on dependentVar
});

Is this possible or anyone know how I can do this ? I need to do this because dependentVar contains C# code ?

1
  • $(document).load('script.js'), function(){ }); Commented Jun 23, 2011 at 18:13

2 Answers 2

1

This sounds like a design flaw. Instead of loading the code on the fly, can you encapsulate it in a function and pass dependentVar as a parameter?

Sign up to request clarification or add additional context in comments.

Comments

0

You mean like this?

$.getScript("somescript.js", function() {

   var dependentVar = //stuff;

    //insert script here which depends on dependentVar
    if(dependentVar) {
        $.getScript("somescript2.js", function() {

        });    
    }
});

2 Comments

are you sure this works because just tried it and can't seem to get it working ?
so dependentVar = <%: someC#Var %>? I am not sure how dependentVar is populated.

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.