JS中获取JSON文件中的数据

  • 1、使用 Ajax 方式获取
$.get("json/test.json", function(data) {
 	console.log(data.total);
});

另一种方式:

$.ajax({
     type: "get",
     url: "json/test.json",
     dataType: "json",
     async: false,
     success: function(data) {
          console.log(data.total);
     }
});
  • 2、使用 getJSON 方式获取
$.getJSON("json/test.json", function(data)  {
     console.log(data.total);
})

以上方式获取到的数据都是 JSON 格式的数据,无需转换,即可使用

如您在阅读中发现不足,欢迎留言!!!

发布了63 篇原创文章 · 获赞 66 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/qq_40065776/article/details/104490792