fengchuanyu 1 týždeň pred
rodič
commit
8de71d3fb8
3 zmenil súbory, kde vykonal 94 pridanie a 0 odobranie
  1. 33 0
      8-ES6/22_异步.html
  2. 33 0
      8-ES6/23_ajax.html
  3. 28 0
      8-ES6/24_JSON.html

+ 33 - 0
8-ES6/22_异步.html

@@ -0,0 +1,33 @@
+<!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>
+        // js 单线程 同一时刻只能处理一件事
+        // 异步 不会阻塞代码的执行 会放到任务队列中
+        // setTimeout(function(){
+        //     console.log("hello world");
+        // },1000);
+        // console.log(1);
+
+        // js 中分为同步代码和异步代码
+        // 常见的异步 定时器 
+        // 当js碰到异步代码会直接放到任务队列中 会继续执行同步代码
+        // 当同步代码执行完毕后 会从任务队列中取出异步代码执行
+        // 如果任务对列中有可以执行的代码放到同步代码执行栈中执行
+        // 然后再去任务队列中查找可以执行的代码
+        // 这种机制 事件循环机制
+
+
+        setTimeout(function(){
+            console.log(1);
+        },0);
+        console.log(2);
+
+    </script>
+</body>
+</html>

+ 33 - 0
8-ES6/23_ajax.html

@@ -0,0 +1,33 @@
+<!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>
+        // 前后端交互一般传输的是字符串 JSON字符串
+        
+
+
+        // 第一步创建XMLHttpRequest对象;
+        let xhr = new XMLHttpRequest();
+        // 第二步 调用open方法 配置请求信息 两个参数第一个请求方式 第二个请求地址(请求接口)
+        xhr.open("GET","http://shop-api.edu.koobietech.com/prod/tagProdList");
+        // 第三步 发送请求
+        xhr.send();
+        // 第四步 监听响应
+        xhr.onreadystatechange = function(){
+            if(xhr.readyState == 4 && xhr.status == 200){
+                // xhr.responseText 服务端返回的数据
+                let jsonStr = xhr.responseText;
+                // 服务端返回的数据为JSON字符串
+                // 把JSON字符串转换为对象
+                let obj = JSON.parse(jsonStr);
+                console.log(obj);
+            }
+        }
+    </script>
+</body>
+</html>

+ 28 - 0
8-ES6/24_JSON.html

@@ -0,0 +1,28 @@
+<!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>
+        // JSON 字符串 它里面一般都是对象格式的
+        // let jsonStr = '{"name":"张三","age":18}';
+        // 把JSON字符串转换为对象 JSON.parse()
+        // console.log(jsonStr)
+        // let obj = JSON.parse(jsonStr);
+        // console.log(obj);
+
+
+        let obj = {
+            name:"张三",
+            age:18,
+            sex:"男"
+        }
+        // 把对象转换为JSON字符串 JSON.stringify()
+        let jsonStr = JSON.stringify(obj);
+        console.log(jsonStr);
+    </script>
+</body>
+</html>