base app.js
This commit is contained in:
parent
cda83d354f
commit
5b5fdfb943
52
assets/js/app.js
Normal file
52
assets/js/app.js
Normal file
@ -0,0 +1,52 @@
|
||||
async function getJson(url,headers={}) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
return await response.json();
|
||||
} catch {
|
||||
return ({
|
||||
status: 0,
|
||||
body: {}
|
||||
});
|
||||
}
|
||||
}
|
||||
async function getText(url, headers={}) {
|
||||
try {
|
||||
const response = await fetch(url);
|
||||
return ({
|
||||
status: response.status,
|
||||
body: await response.text()
|
||||
});
|
||||
} catch {
|
||||
return ({
|
||||
status: 0,
|
||||
body: ""
|
||||
});
|
||||
}
|
||||
}
|
||||
async function postJson(url,data = {},headers={}) {
|
||||
try {
|
||||
headers["content-type"] = "application/json";
|
||||
const response = await fetch(url,{method: "post", headers: headers,body: JSON.stringify(data)});
|
||||
return await response.json();
|
||||
} catch {
|
||||
return ({
|
||||
status: 0,
|
||||
body: {}
|
||||
});
|
||||
}
|
||||
}
|
||||
async function postText(url,data = {},headers={}) {
|
||||
try {
|
||||
headers["content-type"] = "application/json";
|
||||
const response = await fetch(url,{method: "post", headers: headers,body: JSON.stringify(data)});
|
||||
return ({
|
||||
status: response.status,
|
||||
body: await response.text()
|
||||
});
|
||||
} catch {
|
||||
return ({
|
||||
status: 0,
|
||||
body: ""
|
||||
});
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user