请教:javascript访问禁止,如何解决,感谢!

caulxjxys 2013-04-08 05:06:20
刚入手,应该是比较简单的问题,但对于我来说还未找到如何解决,在此请教各位大拿该如何处理。。。

情景描述:
在ubuntu下安装了nginx+php5,在/var/www/目录下放置三个文件:index.html,jquery-1.9.1.min.js,test.php,
index.html文件如下:
<html>
<head>
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script language="javascript">
function show(json) {
alert(json);
}

$(document).ready(function() {
$.getJSON(
"test.php", // The server URL
{ id: 567 }, // Data you want to pass to the server.
show // The function to call on completion.
);

});
</script>
</head>

<body>
JSON Test Page.
</body>
</html>

测试目的:
在index.html和test.php之间测试传递json数据

网页输入地址:http://localhost/index.html,打开web console后台跟踪,发现如下错误信息:
[15:03:06.707] GET http://localhost/index.html [HTTP/1.1 304 Not Modified 0ms]
[15:03:06.881] GET http://localhost/jquery-1.9.1.min.js [HTTP/1.1 403 Forbidden 0ms]
[15:03:06.835] ReferenceError: $ is not defined @ http://localhost/index.html:15
[15:03:06.837] The character encoding of the HTML document was not declared. The document will render with garbled text in some browser configurations if the document contains characters from outside the US-ASCII range. The character encoding of the page must to be declared in the document or in the transfer protocol. @ http://localhost/index.html
...全文
206 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
或者干脆用别人的 http//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  • 打赏
  • 举报
回复
chmod 775 /var/www/jquery-1.9.1.min.js
clark_kidd 2013-04-10
  • 打赏
  • 举报
回复
[15:03:06.881] GET http://localhost/jquery-1.9.1.min.js [HTTP/1.1 403 Forbidden 0ms] 没权限啊? 是配置问题吧?试试把文件的属性->安全中加入 everyone 账户?
functionsub 2013-04-08
  • 打赏
  • 举报
回复

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; chatset=utf-8" />
<script type="text/javascript" src="jquery-1.9.1.min.js"></script>
<script language="javascript">
function show(json) {
alert(json);
}

$(document).ready(function() {
        $.getJSON(
        "test.php", // The server URL
        { id: 567 }, // Data you want to pass to the server.
        show // The function to call on completion.
        );

});
</script>
</head>

<body>
JSON Test Page.
</body>
</html>
看起来是因为你html文件用的是ascii编码格式的原因,先用记事本打开index.html,然后另存问,注意在名字下面,有一个下拉菜单,选择UTF8编码, 再把文件的代码改成这样试试看。

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧