I am using this answer, the ever popular SO post to dynamically load a javascript file:
$.getScript("scripts/datagrid.js", function(){
alert("Script loaded but not necessarily executed.");
});
But the it never loads. JQuery is referenced in the underlying HTML file in the header before the js file that is calling this script loading function. Furthermore, I don't call this script loader until after the document is loaded:
$(document).ready(function() {
administration.init();
});
var administration = {
...
init : function() {
try {
$.getScript("scripts/datagrid.js", function(){
alert("Script loaded but not necessarily executed.");
});
} catch (e) {
alert('[administration.init] error = ' + e);
}
...
I have validated that JQuery is loaded already by checking the value of an element that is hard-coded in HTML using JQuery. Which is also validated by the fact the script is executed.
The script file exists and works if I add it to the HTML header, but I want to load it dynamically.
Why does the anonymous function never fire (obviously because the script never loads - why)?
EDIT
Following Sanjay's advice below, I bound the error handler to the ajax call and the console now displays the following:
TypeError: Cannot read property 'init' of undefined(…)
So it's finding the file, just not apparently able to find the init function of the class.