简体   繁体   中英

Including JQuery library

I have the following file organization:

Project > SubFolder1> SubFolder2> Subfolder3> Test.aspx

and I am trying to include Jquery library from

Project> Scripts

in test page I did both:

<script src="~/Scripts/jquery-1.9.1.js"></script>

and

<script src="../../../Scripts/jquery-1.9.1.js"></script>

but it gives me that the resource cannot be found and the URI in source view is:

localhost:44388/Project/SubFolder1/SubFolder2/SubFolder3/~/Scripts/jquery-1.9.1.js

How can I include the library correctly?

Try this (without tilde):

<script src="/Scripts/jquery-1.9.1.js"></script>

Or if you are in an ASP.NET MVC context:

<script src="@Url.Content("~/Scripts/jquery-1.9.1.js")"></script>

I would suggest keeping all the javascript files in a seperate folder in the ROOT folder and name it ' js '.

For ex if your root folder is PROJECTS , then make a new folder ' js ' and paste all you javascript and jquery files in this folder then you can reference this files in this manner

<script src="js/jquery-1.9.1.js"></script>

我必须像这样包括它

<script src="/Project Name/Scripts/jquery-1.9.1.js"></script>

You could use a CDN for these kind of universally known, general purpose libraries.

A Content Delivery network gives you the advantage of faster load time, because of the clients will be served by the nearest/fastest server (less network latency), and of course, if the client already visited some other website which also made use of jQuery over the CDN, there's a big chance the file is already in the browsers cache, so no download of the file is actually needed.

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

See http://jquery.com/download/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM