DWilliams Posted December 23, 2011 Share Posted December 23, 2011 First things first I'm terrible with JavaScript so I'm muddling through almost everything I do with it My basic goal here is that I need to "include" a list of JS files into my main file and pause execution of my main script until they're loaded. After some googling I've found jQuery's getScript() method. I tried to make a script loader function based on my (working) image preloader. Here's my code: function loadScripts(callback) { var scripts = new Array('cCell.js', 'cPlayer.js'); var loadedScripts = 0; var numScripts = scripts.length; for(var i = 0;i < numScripts;i++) { $.getScript(resPath + 'js/' + scripts[i], function() { if(++loadedScripts >= numScripts) callback(); }); } } resPath is defined outside that function but I have checked to verify the paths it creates is a valid path to my script. No matter what I try, the callback never seems to get called. At first I had resPath set to be a complete URL to my resource folder. I read somewhere that JS has security features to prevent executing code from a remote URL or something so I tried replacing it with both relative and absolute paths to no avail. What am I doing wrong? Link to comment https://forums.phpfreaks.com/topic/253738-making-a-script-loader-with-jquery/ Share on other sites More sharing options...
shaiang Posted December 25, 2011 Share Posted December 25, 2011 Is the resPath is just a string with path inside it? I tried only with the scritps and it seems to work fine. Link to comment https://forums.phpfreaks.com/topic/253738-making-a-script-loader-with-jquery/#findComment-1301251 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.