ajax getJSON用例:
$.getJSON('./' + mapCode + '.json',
function (data) {
if (data) {
console.log(data);
}
})
fetch用法:
fetch('./data/' + mapCode + '.json', {
method: 'GET',
mode: 'cors',// 允许发送跨域请求
credentials: 'include'
}).then(function (response) {
//打印返回的json数据
response.json().then(function (data) {
if (data) {
console.log(data);
}
});
}