开发者

Why does this jQuery code doesn't work (getScript)

I'm trying to use the jQuery 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

<script>
    $.getScript("http://content.bits开发者_如何学Contherun.com/players/UhLR1fcb-Gv5Rv0Kc.js");
</script>

This line isn't executed

Thanks


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.


My Firebug console is reporting that:

$ is undefined

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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜