views:

112

answers:

3

Hello, I'm trying to use the jQuerty getScript function.

But seems like nothing happens - the script isn't called at all.

What's wrong?

here's the page -> http://ultimateclassicmovies.com/uncategorized/botr-test/

The relevant code block is at

$.getScript("http://content.bitsontherun.com/players/UhLR1fcb-Gv5Rv0Kc.js");

this line isn't executed

thanks

A: 

First Off download Firebug for firefox if you aren't already using it!

On the net tab in firebug it shows that you have something being requested from localhost

http://localhost:54321/browser_integration?ts=1281364540718

This will fail on any machine that isn't running the development server locally on port 54321 an may be what is causing your issue as the line

$.getScript("http://content.bitsontherun.com/players/UhLR1fcb-Gv5Rv0Kc.js");

does get hit but there is no transfer completed.

try changing

$.getScript("http://content.bitsontherun.com/players/UhLR1fcb-Gv5Rv0Kc.js");

to

$.getScript("http://content.bitsontherun.com/players/UhLR1fcb-Gv5Rv0Kc.js", function(data, textStatus) { 
    alert(textStatus); 
});

this should fire an alert box when the request is completed telling you the status which may also Identify your problem.

HTH

OneSHOT

EDIT:

I've just tested this using my own script on a remote server and I also get undefined in the alert box even though the script is loading correctly, this only seems to occur if loading the script from a different server that the page was loaded from, scripts loaded from the same domain give a proper status of success.

In your case you aren't using the callback anyway so just remove the function from the getScript call so that it is back how it was originally

$.getScript("http://content.bitsontherun.com/players/UhLR1fcb-Gv5Rv0Kc.js");

As of yet I'm not sure if this is a bug in jQuery or a browser restriction that causes the status to be undefined.

OneSHOT
hi, many thanks for this answer (and also to the 2 other commenters). So i added the code you suggested, and now I get "undefined" at the alert box.what does this mean?http://ultimateclassicmovies.com/horror/the-brain-that-wouldnt-die/
noob
Looking at the site now the script is being loaded correctly but without knowing what the remote script you are loading is doing when it is loaded (anything not wrapped in a function will run as the file is loaded) I couldn't be certain what the undefined error is relating to, it could be an error in your remote script as when everything loads correctly the alert should say success. it may be worth dropping the contents of the remote script into the page temporarily and seeing if it works as expected.
OneSHOT
@noob - See my edit above
OneSHOT
Hi, thanks again for the explanation. So this is a jQuery feature actually, which makes any remote scripts problematic when being injected using getScript(); ?
noob
I Still haven't traced it to jQuery or the browser yet so I couldn't say, it may be due to restrictions imposed by the browser and not due to jQuery at all but without digging deep into the code I'm afraid couldn't say.
OneSHOT
+1  A: 

My Firebug console is reporting that:

$ is undefined

Could be a javascript library-conflict. Try changing it to jQuery.getScript

Simon Scarfe
I see similar:Webpage error detailsUser Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30; MDDR; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; InfoPath.2; OfficeLiveConnector.1.3; OfficeLivePatch.0.0)Timestamp: Mon, 9 Aug 2010 14:47:38 UTCMessage: '$' is null or not an objectLine: 139Char: 5Code: 0URI: http://ultimateclassicmovies.com/uncategorized/botr-test/
Mark Schultheiss
+1  A: 

This is on the end your jQuery include:

jQuery.noConflict();

On the end of this file: http://ultimateclassicmovies.com/wp-includes/js/jquery/jquery.js?ver=1.4.2

This makes $ useless in the page itself, you'll need to use jQuery.getScript() instead. I assume WordPress does this to avoid conflicts with prototype and other libraries, but whatever the reason, it's the source of your current issue. Just replace $ with jQuery where you want to use it and you're all set.

Nick Craver