Loading local JSON file

前端 未结 23 1604
悲哀的现实
悲哀的现实 2020-11-22 01:28

I\'m trying to load a local JSON file but it won\'t work. Here is my JavaScript code (using jQuery):

var json = $.getJSON("test.json");
var data = e         


        
23条回答
  •  名媛妹妹
    2020-11-22 01:41

    I haven't found any solution using Google's Closure library. So just to complete the list for future vistors, here's how you load a JSON from local file with Closure library:

    goog.net.XhrIo.send('../appData.json', function(evt) {
      var xhr = evt.target;
      var obj = xhr.getResponseJson(); //JSON parsed as Javascript object
      console.log(obj);
    });
    

提交回复
热议问题