简体   繁体   中英

CDNs are working fine but not a local hosted script on ASP.NET

I've been trying to access any script in my ASP.NET (Web Forms) application but it doesn't work. I'm able to access the file through the server therefore the destination is fine but the file doesnt seem to be loaded locally.

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

I've tried changing the access path and it doesn't change anything. Though, it works just fine if i use the CDN :

<script src='https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.4.0/fullcalendar.js'></script>

I've had this issue before as I have never been able to access any JQuery or Bootstrap locally hosted scripts. Though, I'm right now facing an issue as I need to modify a line in the .js file and can't do it with the CDN. Any ideas ?

The script is trying to be called from the same directory as the ASPX page. If it's not in the same directory, then it will not load. When you load it from a CDN you have the full path and there's no 404 error.

If you use Chrome's dev tools (F12) or FireBug in Firefox then you should be able to see if it's a 404 error causing the problem.

You need to make it relative to the page or start from the root of the site.

If the script fullcalendar.js is in the root directory and the page is being called from http://somedomain.com/apath/here.aspx then it will fail.

To start from the root of your site, use:

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

If it's in the root folder, or

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

If it's in the scripts folder of your ASP.NET project.

If you just need to "go up" a level you can use (the .. is to go up a folder)

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

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