-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
53 lines (52 loc) · 1.55 KB
/
script.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
45
46
47
48
49
50
51
52
53
function login(){
var pw = document.getElementbyID("password");
fetch("http://192.168.178.105/api/login"),
{
method: "POST",
credentials:"same-origin",
headers: {"Content-Type": "application/json"},
body: JSON.stringify({password: pw})}
.then(function(res){
console.log(res)
if (res.status == 200){
window.location.href="/loggedin.html";
}
else{
alert("Falsches Geheimnis")
}
})
.catch(function(error) {
console.error('Error:', error);
})
}
function urlshort() {
if (document.getElementById("linkeingabe").value !== "") {
var url = document.getElementById("linkeingabe").value;
var ausgabe = document.getElementById("linkausgabe");
fetch("http://localhost:13000/api/shorten", {
method: "POST",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
link: url
})
}).then(function (res) {
console.log(res);
if (res.status == 200) {
res.json().then((data) => {
const short = data.short;
console.log(short);
ausgabe.innerHTML = short;
});
}
else {
alert(res.status + ": Fehler");
}
})
.catch(function (error) {
console.error('Error:', error);
})
}
};