I'm using $.getScript to load the script files, this works fine. if I check the network tab in my browser, the file did download successfully.However, when I try and use functions in the script file they are undefined. There also is no new script tag in the HTML.
How do I use the new script file once it has been downloaded?
Note: The file also does not show up in the resources tab of the dev tools after it has been downloaded.
Edit: added code below and some more info
Script being loaded file:
var STUD = function () { return { STUDLoaded: function () { alert('Working!'); } } } function foo() { alert('bar!'); } js downloading the script file and calling the functions.
$.getScript(gSiteRoot + 'Scripts/Views/' + ControllerName + '.js') .done(function (script, textStatus) { debugger; foo(); if ($('#hdnJSClass') != undefined) window[$('#hdnJSClass').val()][$('#hdnJSClassFunc').val()](); }) .fail(function (jqxhr, settings, exception) { GEN._displayNotification('Error', 'There was an error loading the page, please retry', true); }); The function foo fires correctly when called after the async loading. So the issue is with the window call, this call works for my other js functions, but not the dynamically loaded ones.
$.getScriptdownloads the script via AJAX and evaluates it locally. You will neither see<script>tag nor you will see it as a resource. If it doesn't work then you probably have an error somewhere in the script. Since it is a custom way to download js it will be difficult to debug it. Show us the code.window[$('#hdnJSClass').val()]object? Iffoo()works then.getScript()works too. The problem is with the function stored in object (or the object) that you are looking for