开发者

Django : jQuery not loading

I want to use jquery in my django project but I can't seem to be able to load the jquery file as my simple function just doesn't do anything.

I put the jquery.js file in the same folder than my view and I call it this way

<script type="text/javascript" src="jquery.js"></script>

But then when I try a simple function, it does nothing when I click on a link

<script type="text/javascript">
$(document).ready(functio开发者_Go百科n(){
    $("a").click(function(){
        alert("mii");
    });
});
</script>

Why isn't it loading the jquery file ?


There are several possible problems:

  1. The path to "jquery.js" is relative. Does it exist in the same webserver directory as your HTML page, and is it accessible? You can try to load the script in your browser to see if you get a 404 error.

  2. Are any errors displayed on the Javascript console?

  3. Is jquery.js a clean copy from jquery.com or has it been modified?

An easy way to get around library-related problems is to use one of the CDNs (Content Delivery Networks) to provide the script for you. For example, you can use:

<script src="http://code.jquery.com/jquery-1.6.1.min.js"></script>

This ensures that no errors are introduced into the library locally, allows the script to be used from cache if it was already loaded on another site, and can provide faster results to the user based on the CDN's geographic layout. Please see the "CDN HOSTED JQUERY" section at Downloading jQuery for more information.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜