I want to load a javascript function from a text file over ajax (using jQuery) but cannot seem to be able to get it right.
This is my javascript function which I want to load from a text file (abc.js):
function my_alert() { alert 1; }
This is how I use ajax to read the file:
$.getScript('abc.js', function (script) {
var loaded_function = ???
});
How do I assign loaded_function so that I can call my_alert
using loaded_function.my_alert()
?
EDIT
The reason I do not want to create new <script>
tags or use $.getScript
is that my_alert
then lives in the global context. I want it to only live inside the { }
function scope.
Is this possible?