Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>请求返回状态判断</title> | ||
<meta charset="utf8"> | ||
</head> | ||
<body> | ||
<h1>请求返回状态判断</h1> | ||
<p>服务端返回的内容: <span id="result"></span></p> | ||
|
||
<script> | ||
function doFetch (status) { | ||
fetch('/api/check_state?status=' + status) | ||
.then(response => { | ||
if (response.ok) { | ||
return response.text(); | ||
} else { | ||
throw new Error(`${response.statusText}(${response.status})`); | ||
} | ||
}) | ||
.then(result => { | ||
console.log(`成功啦!返回结果:${result}`); | ||
}) | ||
.catch(error => { | ||
console.log(`出错啦!出错原因:${error.message}`); | ||
}); | ||
} | ||
doFetch(200); | ||
doFetch(404); | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>设置请求首部</title> | ||
<meta charset="utf8"> | ||
</head> | ||
<body> | ||
<h1>设置请求首部</h1> | ||
<p>服务端返回的内容: <span id="result"></span></p> | ||
|
||
<script> | ||
var options = { | ||
headers: { | ||
'X-MY-HEADER': 'X-MY-VALUE' | ||
} | ||
}; | ||
fetch('/api/setting-request-header', options) | ||
.then(response => response.text()) | ||
.then(result => { | ||
console.log(`result is : ${result}`); | ||
}); | ||
</script> | ||
</body> | ||
</html> |