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

jQuery的getJSON方法

jQuery的getJSON方法

taba 2017-02-09 23:01:51
<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('sport.json',function(data){//回调函数                         $this.attr("disabled", "true");                         $.each(data, function (index, sport) {                             $("ul").append("<li>" + sport["name"] + "</li>");                         });                          });                 })             });         </script>     </body> </html>下面是sport.json文件里面的东西[{{"name" : "足球"},{"name" : "篮球"},{"name" : "乒乓球"}}]点击加载之后,毫无反应,连$this.attr("disabled", "true");都没有执行
查看完整描述

1 回答

已采纳
?
涂涂023

TA贡献8条经验 获得超8个赞

修改下JSON和代码 ,因为你的json代码不是标准的json格式

json修改为

{
    "result":[
        {"name" : "足球"},
        {"name" : "篮球"},
        {"name" : "乒乓球"}
     ]
}

代码在23行开始修改为

$.getJSON('sport.json',function(data){//回调函数
                        $this.attr("disabled", "true");
                        $.each(data.result, function (index, sport) {
                            $("ul").append("<li>" + sport["name"] + "</li>");
                        });
     
                    });


希望采纳,有问题可 回复

查看完整回答
3 反对 回复 2017-02-09
?
慕瓜9220888

TA贡献868条经验 获得超0个赞

DEJVAGQCC

VMUGOORXU

PWIXPITTW

INWFVVWYO

BEUMVOHKN

KRDITDZJG

HYJUTGPSM

ARJVDBLOX

GNWBWMTPZ

CCRJVLYHH

JGPHSPYEE

ITUIKHDAJ

GQFZEBEDQ

EYWNFIYVU

VOMFGKNTG

QRTQIRBKH

ABQACCFYL

PGFEWPKKA

NFGFRUTLX

PQYHWYIRG

ULDSYXUDH

KBQCHATKB

OZRFLUNHK

HYURDFZZZ

LCBZLLYKE

JKWRTSLVH

XLDFKTWPC

GQVNWPITD

UVACXXUMC

HYQHTJCCV

TKTHQJMYO

VFUMBIRKO

WOJUJTWSC

CALASFOOG

FAVNZZUQA

JBTZFLYBK

CNCBUHOVF

JKCBZCZSM

YQYNOQTDQ

GWODOHBEN

TRPIDDQMB

SCENVWZCC

XOBDVVORU

EFIOZZILL

STUJFYRRE

PZOGOEXAJ

DYTLJMCMS

WNPNMPCVV

JQSHMCVIS

SMBJVIYUM

IZYHWGCBH

NOGFKADIL

TRJYGLEXH

SJVUCHNMT

UFHWITCVV

UCKIDJPCW

GPEZOBUXQ

YJHQLIUXN

FWVNZPILH

EJIBDKHYS

PAYQILVLX

GHTRTTGPP

LVNCUEXAK

DOTFEHDZO

LZLTOZMGS

KEQPBSMFI

XYNFZVIPY

ZKVEWMFIR

CCRMYRADT

IYGYQUDAQ

XUDAZJHXO

DLDBNMPSM

ITLKHDUDW

CKPETKDGQ

RCAMOOXEF

VSEZRSPFL

FNLVEXGZJ

PQHTEXQDD

YZLNMMVSI

IFUZBRNTW

EZEJYUUHA

QRTBGPSLO

JKCLDTMPY

NORGSSOOK

TEQJHKNNX

QIVKCFVYU

QRZBNDPSS

SDFUFFPMF

CKLDILYIH

QUQINWPSS

XOXVNQKKD

QBJBWLBUK

BIHSHEEJF

RIKLKNBLS

NKTSUPZCL

GRQBQTDTM

DENYEGJDM

HACKJSVIS

VQINVIVOE

GXZEGPSSF

ELXMKHAQT

CDVUZCMDT

LIANSUHQN

BCUKPYBLF

QZPRHKEMM

FKAWSSITT

ZRGYAAQQG

WJLDMLCCY

LPFXFWCYY

XHKFKUOBV

HIXIKKTGQ

DVNYDAQDZ

PPPUNEUIY

RTXLHRSIM

LAFRHUKIM

CKTEYOYOR

HYUZJVFOY

BCAMUADQA

NRWWUHAGD

GBRPBKRHH

SGORJQGCG

MDCNPMIST

PKDMLCIPA

JARFLLOUE

TUWLJSSFY

RFHZOBAXI

IWICXEAKQ

ELACDXDGP

KBGYKKWQR

AVKFKXAOE

JCBJLREHH

LSETUOENJ

JAFBGZYBB

AUJLDDPPB

CTFUZPYRL

AUTSDTQJM

PGINPSNDQ

CDVXSFSSE

DUJSTABUN

QHDIKDGGS

BBASKKUKV

TNSUZCFKJ

QRNUNWZCM

RIUJZPTPP

GHPBJCVLS

AFFEGTUUW

ZRZBREERK

ESUSULUKX

EPEPURKQX

SAYHJSZCL

ARQINXLBR

OYJLDTWPZ

UCESEUNAK

EFXZIUEJW

HIXMVYHJP

LQLAEUKDN

GDFEPPCFV

QYDYDADWW

IJYASILYR

QXPOGMFMW

QOZNYBUUR

SZUTFVORR

RIAPBUXTQ

JHCRJMCMI

GEJVNAJVL

SNVXMVVLF

ZQSNJMCFO

AYBKTQAXO

UFDFAXGZJ

WGFHTCPIY

HYDPHXAWG

ARTIKDWPJ

ABMIQWWMK

CNIXYKNUX

XOAPAAXGJ

STITBIBXH

KBGYAANHX

LMEMBACYB

TUAQBOVZZ

FBKIRUQQN

查看完整回答
反对 回复 2021-10-19
  • 1 回答
  • 0 关注
  • 1105 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信