jQuery.getScript():
The script is executed in the global context, so it can refer to other variables and use jQuery functions.
From the documentation, it seems that your variable should be accessible within a $.getScript(function(){..})
call. Therefore, this is likely a problem with scope. Your variable my_variable
exists (presumably) inside $(document).ready(function(){...})
, and is therefore restricted to that particular scope.
Try using a global variable by assigning your data to the window object:
// Set it as a global variable by assigning it to the window object
window.my_variable = 'some value';
// Now use it inside of $.getScript()
$.getScript( "my_script.js", function() {
// Access it by name
alert(my_variable);
// or as a property of window
alert(window.my_variable);
// both ways to access my_variable work and are valid.
}
Sources: old question here and $.getScript docs here.
Verified on my personal server.