JSON数据加载 发表于 2017-04-06 | 分类于 js高级教程 | json数据加载123456789101112131415161718192021222324案例分析var box = document.querySelector('div')var btn = document.querySelector('button')btn.onclick = function(){ var xhr = new XMLHttpRequest(); //输入网址,参数一是请求方式 xhr.open('get','true') //发起请求 xhr.send(); xhr.onreadyStateChange = function(){ if(xhr.readyState===4){ if(xhr.status===200){ console.log(xhr.responseText) function json_callback(data){ console.log(data) } //利用javaScript的src不存在跨域问题,相当于函数参数调用,参数是我们需要的数据 json_callback({ name:'jsonData' }) } } } } 跨域:不同域相互请求资源