刚入手,应该是比较简单的问题,但对于我来说还未找到如何解决,在此请教各位大拿该如何处理情景描述:
在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.htmlJavaScript访问禁止

解决方案 »

  1.   


    <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编码,
    再把文件的代码改成这样试试看。
      

  2.   

    [15:03:06.881] GET http://localhost/jquery-1.9.1.min.js [HTTP/1.1 403 Forbidden 0ms]
    没权限啊?
    是配置问题吧?试试把文件的属性->安全中加入 everyone 账户?
      

  3.   

    chmod 775 /var/www/jquery-1.9.1.min.js
      

  4.   

    或者干脆用别人的 http//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js