- 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 格式的数据,无需转换,即可使用
如您在阅读中发现不足,欢迎留言!!!