为什么我的代码运行之后加载不出来咧,在谷歌和IE浏览器都试过了

来源:1-2 使用getJSON()方法异步加载JSON格式数据

十年树木_百年眼袋熊

2018-03-23 10:09

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <title>使用getJSON()方法异步加载JSON格式数据</title>

        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js" type="text/javascript"></script>

        <link href="style.css" rel="stylesheet" type="text/css" />

    </head>

    

    <body>

        <div id="divtest">

            <div class="title">

                <span class="fl">我最喜欢的一项运动</span> 

                <span class="fr">

                    <input id="btnShow" type="button" value="加载" />

                </span>

            </div>

            <ul></ul>

        </div>

        

        <script type="text/javascript">

            $(function () {

                $("#btnShow").bind("click", function () {

                    var $this = $(this);

                    $.getJSON("http://www.imooc.com/data/sport.json",function(date){

                        $this.attr("disabled", "true");

                        $.each(date, function(index,sport){

                            if(index==3)

                            $("ul").append("<li>" + sport["name"] + "</li>");

                        });

                    });

                })

            });

        </script>

    </body>

</html>


写回答 关注

4回答

  • 慕九州0167811
    2022-08-09 23:15:49

    奥,明白了,我也在纠结这个问题

    mwkgq

  • 幕布斯9266291
    2022-04-05 03:34:26

    good,如果你能把代码再缩进一下就更完美了

    ptlsdozeuzjchjeh 是恐惧,一边是淡然07 度政客:火龙果改名之后就代表我们"驯 我们已重回正轨克洛普英超5次KO穆帅!等于爵爷温格

  • 彈指
    2018-04-11 11:14:32

    改这两个地方: <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" type="text/javascript"></script>

    加s:"https://www.imooc.com/data/sport.json"我的谷歌可以运行

    qq_孔洁钰...

    终于在评论找到解决方案了

    2018-06-11 09:35:07

    共 1 条回复 >

  • 慕容77
    2018-03-23 14:31:32

    第五行:<script src="https://www.imooc.com/static/lib/jquery/1.9.1/jquery.js"></script>

    添加的代码位置   $.getJSON("https://www.imooc.com/data/sport.json",function(date){

    所有的http改为https

jQuery基础(五)一Ajax应用与常用插件

如何用jquery实现ajax应用,加入学习,有效提高前端开发速度

69095 学习 · 400 问题

查看课程

相似问题