From 3405fdd21be03086a94b1797db55629468e2d3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=94=A1=E7=8E=AE=E9=93=AD?= <2373854303@qq.com> Date: Mon, 2 Dec 2024 23:51:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A41202=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20241202 XHR\344\270\216AXIOS.md" | 453 ++++++++++++++++++ .../html\346\226\207\344\273\266/index.html" | 206 ++++++++ .../html\346\226\207\344\273\266/update.html" | 170 +++++++ 3 files changed, 829 insertions(+) create mode 100644 "\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" create mode 100644 "\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" create mode 100644 "\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" diff --git "a/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" new file mode 100644 index 0000000..6178d87 --- /dev/null +++ "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" @@ -0,0 +1,453 @@ +## 课堂笔记 + +#### **XHR** + +```javascript +// 创建一个 XMLHttpRequest 对象 +const xhr = new XMLHttpRequest(); + +// 使用 +// GET +xhr.open('GET', 'https://api.example.com/data', true); +xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === 200) { + console.log(xhr.responseText); // 处理响应 + } +}; +xhr.send(null); + +// POST +xhr.open('POST', 'https://api.example.com/submit', true); +xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8'); +xhr.onreadystatechange = function() { + if (xhr.readyState === 4 && xhr.status === 200) { + console.log(xhr.responseText); + } +}; +// 假设我们发送的是 JSON 格式的数据 +const data = JSON.stringify({key1: 'value1', key2: 'value2'}); +xhr.send(data); +``` + +#### **AXIOS** + +```javascript +// 导入 + + +// 使用 +// GET +axios.get('https://api.example.com/data') + .then(function (response) { + // 成功处理 + console.log(response.data); + }) + .catch(function (error) { + // 错误处理 + console.error(error); + }); + +// POST +// 发送 JSON 数据 +axios.post('https://api.example.com/submit', { + key1: 'value1', + key2: 'value2' + }) + .then(function (response) { + console.log(response.data); + }) + .catch(function (error) { + console.error(error); + }); +``` + +## 课后作业 + +#### **异步请求响应页面** + +**index.html** + +```html + + + + + + + axios使用 + + + + + +
+
+

查询模块

+
+
    +
  • 加载中···
  • +
+
+
+
+

新增模块

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+ + + + + +``` + +**update.html** + +```html + + + + + + + 修改模块 + + + + + +
+

修改模块

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + + + + +``` + diff --git "a/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" new file mode 100644 index 0000000..29ffcf7 --- /dev/null +++ "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" @@ -0,0 +1,206 @@ + + + + + + + axios使用 + + + + + +
+
+

查询模块

+
+
    +
  • 加载中···
  • +
+
+
+
+

新增模块

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+
+ + + + + \ No newline at end of file diff --git "a/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" new file mode 100644 index 0000000..610ce6d --- /dev/null +++ "b/\350\224\241\347\216\256\351\223\255/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" @@ -0,0 +1,170 @@ + + + + + + + 修改模块 + + + + + +
+

修改模块

+
+
+
+ +
+
+ +
+
+ +
+
+ + +
+
+ + + + + \ No newline at end of file -- Gitee