ggdgsdbsdbbb / static / js / gitly.js
45 lines · 41 sloc · 1023 bytes · 5d8107cb28727996daed016b0c79a9346f864d2b
Raw
1function post(url, dataObj, success) {
2 // Create a FormData object
3 const formData = new FormData();
4
5 console.log(dataObj);
6 if (dataObj !== undefined) {
7 // Populate the FormData object with the object entries
8 Object.entries(dataObj).forEach(([key, value]) => {
9 formData.append(key, value);
10 });
11 }
12
13 // Send the POST request with the FormData object
14 fetch(url, {
15 method: "POST",
16 body: formData,
17 })
18 .then((response) => {
19 /*
20 if (!response.ok) {
21 throw new Error("Network response was not ok");
22 }
23 */
24 return response.json(); // or .text() if the response is not in JSON format
25 })
26 .then((data) => {
27 if (success !== undefined) {
28 //const json_data = JSON.parse(data);
29 success(data);
30 //success(json_data);
31 }
32 //console.log("Success:", data);
33 })
34 .catch((error) => {
35 console.error("Error:", error);
36 });
37}
38
39
40function change_lang(x) {
41 var y = document.getElementById("select_lang");
42 post('/change_lang/' + y.value, {}, () => {
43 window.location.reload();
44 } )
45}
46