-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmsg.html
More file actions
48 lines (47 loc) · 1.31 KB
/
msg.html
File metadata and controls
48 lines (47 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>myMsg</title>
<style></style>
<link rel="stylesheet" href="no.css">
</head>
<body>
<button id="refresh">刷新</button>
<div id="msg"></div>
<script>
function ajax(options) {
options = options || {};
const xhr = new XMLHttpRequest();
xhr.open(options.type, options.url);
xhr.onreadystatechange = function () {
if (xhr.readyState === 4) {
const status = xhr.status;
if (status >= 200 && status < 300 || status === 304) {
options.success && options.success(xhr.responseText, xhr.responseXML);
} else {
options.error && options.error(status);
}
}
};
return xhr;
}
const refresh=document.getElementById("refresh");
refresh.onclick=function (){
getData();
}
const msg=document.getElementById("msg");
function getData(){
ajax({
url: "https://mock.presstime.cn/mock/6648b0e2fa29401478437423/nooneb/myMsg",
type: "get",
success: res => {
const data = JSON.parse(res);
msg.innerText=data.data.msg;
}
}).send()
}
getData();
</script>
</body>
</html>