garyexs 2016-03-24 13:57 采纳率: 0%
浏览 1636
已结题

jQuery 的getjson的回调函数不运行

test.html

<!DOCTYPE html>




click me $(document).ready(function(){ $("button").click(function(){ alert("before getjson"); $.getJSON("test.json",function(data){alert("did it!");}); alert("after getjson"); }); });


test.json

{ "people": [

{ "firstName": "Brett", "lastName":"McLaughlin", "email": "aaaa" },

{ "firstName": "Jason", "lastName":"Hunter", "email": "bbbb"},

{ "firstName": "Elliotte", "lastName":"Harold", "email": "cccc" }

]}

  • 写回答

2条回答 默认 最新

  • ai2018 2016-03-25 00:29
    关注

    本地模式运行会存在同源问题,需要将test.html 和 test.json 放在同级目录下,放在静态文件服务器或者应用服务器上,以服务器模式运行才可以正常
    访问到。

    评论

报告相同问题?