12345678910111213141516171819202122232425262728293031323334353637 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- function ajaxFun(url,foo) {
- // 第一步 创建XMLHttpRequest 对象;
- var xmlh = new XMLHttpRequest();
- // 第二步 发送请求
- xmlh.open("GET", url, true);
- xmlh.send();
- // 第三步 处理请求结果
- xmlh.onreadystatechange = function () {
- if (xmlh.readyState == 4 && xmlh.status == 200) {
- var resObj = JSON.parse(xmlh.responseText)
- // console.log(resObj)
- // return resObj;
- foo(resObj)
- }
- }
- }
- // console.log(ajaxFun("./data/data1.json"));
- ajaxFun("./data/data1.json",function(res){
- console.log(res);
- })
- </script>
- </body>
- </html>
|