为了账号安全,请及时绑定邮箱和手机立即绑定

为什么没有显示效果?

为什么我测试不了?自己放在本地VScode调试也不行,但是打开接口还是看到数据还在的。

正在回答

3 回答

应该是跨域问题吧,我也是这样,最后直接在网页的编辑器里把url改成相对路径就能看到效果了

0 回复 有任何疑惑可以回复我~

可以运行的,请确认你写对了。

<!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="https://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('https://www.imooc.com/data/sport.json', function(data){

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

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

                            if(index==3)

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

                        });

    

                    });

                })

            });

        </script>

    </body>

</html>


1 回复 有任何疑惑可以回复我~

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

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

注意2个http后面都加上s,function内的参数记得加上data

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消
jQuery基础(五)一Ajax应用与常用插件
  • 参与学习       69100    人
  • 解答问题       400    个

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

进入课程

为什么没有显示效果?

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信