$(function(){
//1、成功 打印出Peter
$.getJSON('data.js', function(json) {
console.log(json['programmers'][0]['firstName'])
});
//2、出错
var data = $.getJSON('data.js', function(json) {
return json;
});
console.log(data['programmers'][0]['firstName']);
//3、出错
var data2;
$.getJSON('data.js', function(json) {
data2 = json;
});
console.log(data2['programmers'][0]['firstName'])
})
分析一下出错两种方式为何不可行,为何无法将获取的数据存到全局变量?