/
fetch.html
56 lines (50 loc) · 1.24 KB
/
fetch.html
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
49
50
51
52
53
54
55
56
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>fetch</title>
</head>
<body>
<script>
// fetch header
let mheader = new Headers({
'Content-Type': 'application/json',
'Cache-Type': 'no-cache'
})
function post(url, data) {
return fetch(url, {
method: 'POST',
headers: mheader,
body: JSON.stringify(data),
mode: 'cors'
}).then(function (response) {
return response.json()
})
}
function get(url){
return fetch(url, {
method: 'GET',
headers: mheader,
mode: 'cors'
}).then(function (response) {
console.log(response.json())
return response.json()
})
}
post('https://www.washer.gree.com/login', {
userName: 'susan',
userPassword: '123456'
}).then(function (response) {
console.log(response)
}).catch(function (error) {
console.log(error)
})
get('./assets/data.json').then(function (response) {
console.log(response)
}).catch(function (error) {
console.log(error)
})
</script>
</body>
</html>