Jump to content

Recommended Posts

First things first I'm terrible with JavaScript so I'm muddling through almost everything I do with it :D

 

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.