Defined variables that do not work in javascript files when I use getScript

advertisements

When I use $.getScript the variables in the main javascript file cannot pass to included js file. For example:

var tVar = 'Hello World!';
$.getScript('js/setting.js', function() {
    // My callback code
});

setting.js:

alert(tVar);

How can I pass variables to included file?


May be use a function inside your included js file and pass variable as arguement to that function.