-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathutils.js
44 lines (40 loc) · 1016 Bytes
/
utils.js
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
const EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/
function simplePhpPostRequest(url, credentials, onSuccess, onFailure){
phpRequest(
url,
"POST",
{"Content-Type": "application/json"},
credentials,
onSuccess,
onFailure
)
}
function phpRequest(url, method, headers, credentials, onSuccess, onFailure){
fetch(url, {
method: method,
headers: headers,
body: JSON.stringify(credentials)
})
.then(res => {
onSuccess(res)
})
.catch(reason => {
console.log(reason)
onFailure(reason)
})
}
function getUserData(onSuccess) {
let indexPhpUrl = 'http://localhost:63342/WebProject/index.php'
simplePhpPostRequest(
indexPhpUrl,
{},
res => {
res.json()
.then(res => {
onSuccess(res)
})
},
reason => {
}
)
}