Loading local JSON file

前端 未结 23 2225
悲哀的现实
悲哀的现实 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:49

    I had the same need (to test my angularjs app), and the only way I found is to use require.js:

    var json = require('./data.json'); //(with path)
    

    note: the file is loaded once, further calls will use the cache.

    More on reading files with nodejs: http://docs.nodejitsu.com/articles/file-system/how-to-read-files-in-nodejs

    require.js: http://requirejs.org/

提交回复
热议问题