1 //1.new一个XMLHttpRequest 兼容性写法
2 var xmlhttp;
3 if (window.XMLHttpRequest) {
4 xmlhttp = new XMLHttpRequest();
5 } else {
6 xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
7 }
8 //2.定义请求方式
9 xmlhttp.open("GET", "http://yapi.shangyuninfo.com/mock/156/bookType")
10 //3.向服务器发送请求
11 xmlhttp.send();
12 //4.响应与数据处理
13 xmlhttp.onreadystatechange = function (res) {
14 if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
15 console.log(res.currentTarget.response);
16 var resout = JSON.parse(res.currentTarget.response)
17 console.log(resout.book[0].typeList);
18 }
19 }
20