-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.php
125 lines (102 loc) · 3.35 KB
/
test.php
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.2/axios.min.js"></script>
<script type="text/javascript" async>
async function postData(url = '', data = {}) {
const response = await fetch(url, {
method: 'POST',
credentials: 'include',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
});
return response.json();
}
function ajaxPost(url='',data={}) {
const body = JSON.stringify(data);
return new Promise((resolve,reject) => {
const xhr = new XMLHttpRequest()
xhr.open('POST', url, true)
xhr.setRequestHeader('Content-type', 'application/json')
xhr.withCredentials = true
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr.response);
} else {
reject({
status: xhr.status,
statusText: xhr.statusText
});
}
}
xhr.onerror = () => {
reject({
status: xhr.status,
statusText: xhr.statusText
})
}
xhr.send(body);
})
}
function ajaxGet(url='',data={}) {
const body = JSON.stringify(data);
return new Promise((resolve,reject) => {
const xhr = new XMLHttpRequest()
xhr.open('GET', url, true)
xhr.setRequestHeader('Content-type', 'application/json')
xhr.withCredentials = true
xhr.onload = () => {
if (xhr.status >= 200 && xhr.status < 300) {
resolve(xhr.response);
} else {
reject({
status: xhr.status,
statusText: xhr.statusText
});
}
}
xhr.onerror = () => {
reject({
status: xhr.status,
statusText: xhr.statusText
})
}
xhr.send(body);
})
}
//ajaxPost('http://localhost/dnd_api/accessnode/session/set',{username:"rma"}).then((response) => {
// console.log(JSON.parse(response))
// ajaxGet('http://localhost/dnd_api/accessnode/session/get').then((response) => {console.log(JSON.parse(response))});
//});
//const resp = await ajaxPost('http://localhost/dnd_api/accessnode/session/set',{username:"rma"})
//console.log(resp);
//get one user
postData('http://localhost/dnd_api/accessnode/user/token',{token:"a1234sferds459ifs"}).then((data) => {
console.log(data[0].name); // JSON data parsed by `data.json()` call
});
// get list of users
/*
fetch('http://localhost/dnd_api/accessnode/user/list',{
credentials: 'include'
}).then((data) => {
return (data.json()); // JSON data parsed by `data.json()` call
}).then(post => {console.log(post)});
////////// WARNING /////////////////////// This will blow up your table so just be careful
postData('http://localhost/dnd_api/index.php/user/add',{data:['aaa','abfg234','AAA battery','bej34erkjvs48kjd932','AF321','abcdefghij']}).then((data) => {
console.log(data); // JSON data parsed by `data.json()` call
});
postData('http://localhost/dnd_api/index.php/user/bits').then((data) => {
console.log(data); // JSON data parsed by `data.json()` call
});
*/
</script>
</body>
</html>