javascript 403 Forbidden for Jquery.min.js 在 localhost 上开发时
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26186526/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
403 Forbidden for Jquery.min.js when developing on localhost
提问by MarvinLazer
I've looked all over google and the site and none of the solutions I've tried have worked... maybe my problem requires something a little more specific.
我已经浏览了谷歌和网站,但我尝试过的解决方案都没有奏效……也许我的问题需要更具体的东西。
When I have this site hosted on a test site, it works fine, but I'm getting this error when I use "Inspect Element" on Chrome: Failed to load resource: the server responded with a status of 403 (Forbidden). I can tell the jquery file isn't being accessed properly by my site because the jquery that works perfectly on my Go Daddy test site (a cool little tool called Tablesorter) isn't working anymore.
当我将此站点托管在测试站点上时,它工作正常,但是当我在 Chrome 上使用“检查元素”时出现此错误:无法加载资源:服务器响应状态为 403(禁止)。我可以告诉我的站点没有正确访问 jquery 文件,因为在我的 Go Daddy 测试站点(一个叫做 Tablesorter 的很酷的小工具)上完美运行的 jquery 不再工作了。
The jquery.min.js file is in a directory called js. Here's the entirety of the head in my html file.
jquery.min.js 文件位于名为 js 的目录中。这是我的 html 文件中的整个头部。
<head>
<title>Corporate Dude, Data Management</title>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery.tablesorter.js"></script>
<link rel="stylesheet" type="text/css" href="style.css?v=1.9"/>
<script type="text/javascript">
$(document).ready(function()
{
$("#data_table").tablesorter();
}
);
</script>
</head>
The weird thing is that when I move the style.css file into the js directory and change the path to js/style.css, the css works just fine. Does this mean it's not a permissions issue or is it just a peculiarity of the way href works in the link tag?
奇怪的是,当我将 style.css 文件移动到 js 目录并将路径更改为 js/style.css 时,css 工作正常。这是否意味着这不是权限问题,还是只是 href 在链接标签中工作方式的一个特殊性?
I've tried going to the terminal and typing cd /Users/myusername/mylocalhostfile/"Corporate Guy"/js then typing chmod 0755 to give permission to access the directory, but that didn't work either. Is this the proper way to assign permissions through the terminal?
我试过进入终端并输入 cd /Users/myusername/mylocalhostfile/"Corporate Guy"/js 然后输入 chmod 0755 以授予访问该目录的权限,但这也不起作用。这是通过终端分配权限的正确方法吗?
Thanks for any help you can give me.
感谢你给与我的帮助。
回答by Jorge BCh
I had the same problem: accessing jquery locally would not work but accessing it remotely from "http://code.jquery.com/jquery-1.7.2.min.js" would work. The problem is that when I downloaded jquery it was stored without reading access to everyone (as json_parse... has below):
我遇到了同样的问题:在本地访问 jquery 不起作用,但从“ http://code.jquery.com/jquery-1.7.2.min.js”远程访问它会起作用。问题是,当我下载 jquery 时,它被存储而没有对每个人的读取访问权限(如 json_parse... 如下):
-rw-r----- 1 jorge jorge 94840 ago 6 04:07 jquery-1.7.2.min.js
-rw-r--r-- 1 jorge jorge 9866 jun 25 06:18 json_parse_20091204.js
I changed it thus: chmod +r jquery-1.7.2.min.js
我这样改了: chmod +r jquery-1.7.2.min.js
-rw-r--r-- 1 jorge jorge 94840 ago 6 04:07 jquery-1.7.2.min.js
回答by user2436428
Please check file permissions; it should have read access. I was facing the same issue with AngularJS lib; When I was trying to access it from locally running apache2 server, I was getting: Failed to load resource: the server responded with a status of 403 (Forbidden)
请检查文件权限;它应该具有读取权限。我在使用 AngularJS lib 时遇到了同样的问题;当我试图从本地运行的 apache2 服务器访问它时,我得到:无法加载资源:服务器响应状态为 403(禁止)
The file had not read permissions:
该文件没有读取权限:
-rw-r----- 1 root root 147059 Aug 29 20:20 angular.min.js
-rw-r----- 1 根 147059 八月 29 日 20:20 angular.min.js
Added read-permissions by running:
通过运行添加读取权限:
sudo chmod +r angular.min.js
And now it's working fine.
现在它工作正常。