From 5d652a61dd2eea91c8e144fe5a69803a4780041d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=8B=E5=87=AF=EF=BC=88=E5=BF=97=E4=B8=87=E4=BC=A0?= =?UTF-8?q?=E5=AA=92=EF=BC=89?= <1509501143@qq.com> Date: Tue, 3 Dec 2024 13:17:34 +0800 Subject: [PATCH] 1 --- .../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 "\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" create mode 100644 "\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" create mode 100644 "\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" diff --git "a/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" "b/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/20241202 XHR\344\270\216AXIOS.md" new file mode 100644 index 0000000..6178d87 --- /dev/null +++ "b/\345\256\213\345\207\257/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/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" "b/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/index.html" new file mode 100644 index 0000000..29ffcf7 --- /dev/null +++ "b/\345\256\213\345\207\257/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/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" "b/\345\256\213\345\207\257/20241202 XHR\344\270\216AXIOS/html\346\226\207\344\273\266/update.html" new file mode 100644 index 0000000..610ce6d --- /dev/null +++ "b/\345\256\213\345\207\257/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