Loading local JSON file

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

    In a more modern way, you can now use the Fetch API:

    fetch("test.json")
      .then(response => response.json())
      .then(json => console.log(json));
    

    All modern browsers support Fetch API. (Internet Explorer doesn't, but Edge does!)

    source:

    • Using Fetch

    • Fetch in Action

    • Can I use...?

提交回复
热议问题