开发者社区> 问答> 正文

JS中用getJSON访问一个JSON文件,不知道哪里出错了

 <!DOCTYPE html>
<html>
    <head>
        <title>联系人</title>
        <script src="C:/Users/dell/Desktop/me/jquery/jquery.js" type="text/javascript"></script>
    </head>

    <body>
        <input id="contect" type="button" value="联系人" />
        <span></span>
        <script type="text/javascript">

        $(function () {
            $("#contect").bind("click", function () {
                $.getJSON("C:\Users\dell\Desktop\friends-info.json",function(data){
                    $.each(data, function (index, json) {
                        $("span").append("<h3>"+json.result.categories.name+"</h3>")//.appendchild("<ul></ul>").append("<li>" +  + "</li>");
                    });
                });
            })
        });

    </body>
</html>

展开
收起
小旋风柴进 2016-03-16 17:02:54 2696 0
1 条回答
写回答
取消 提交回答
  • 路径不要用物理路径,用相对路径。用物理路径js文件中注意转义

    本地测试不要用chrome,无法用ajax请求本地文件。

    楼主最好先搞清楚路径,做网页能用物理路径的基本知识肯定很差

    $.getJSON("C:\\Users\\dell\\Desktop\\friends-info.json"

    2019-07-17 19:04:07
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
JavaScript函数 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载