119 method,
120 headers: {
121 "Content-Type": "application/json",
122 Authorization: "Bearer " + (await getCookie("tokenValue")),123 },
124 },
125 );
114/* This is an example for calling this function: fetchPage("api/page/", "GET", page) */
115export async function fetchPage(url, method, page) {
116 const res = await fetch(
117 "http://" + location.hostname + ":8080/" + url + page,118 {
119 method,
120 headers: {
97 method,
98 headers: {
99 "Content-Type": "application/json",
100 Authorization: "Bearer " + (await getCookie("tokenValue")),101 },
102 body: JSON.stringify(body),
103 });
933. The function returns a json object of the fetched data. */
94
95export async function fetcher(url, method, body) {
96 const res = await fetch("http://" + location.hostname + ":8080/" + url, { 97 method,
98 headers: {
99 "Content-Type": "application/json",
50 document.cookie.split(";").forEach(function (c) {
51 document.cookie = c
52 .replace(/^ +/, "")
53 .replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); // Sets every cookie as expired to delete them 54 });
55 await goto("/");
56 location.reload();
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = `Hello, ${name}!`;
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
var str = "Hello, " + "World!";