internetprogrammierung/js/contentloader.js

70 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-05-26 14:33:15 +02:00
window.addEventListener('load', async () => {
console.log("Seite geladen");
//getNewUniqueLink();
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
2018-05-26 14:33:15 +02:00
})
async function getNewUniqueLink() {
try {
var firstFetch = await fetch('php/generateLink.php');
var jsonFirstFetch = await firstFetch.json();
var content = document.getElementById('content');
content.innerHTML = `${jsonFirstFetch.html}`;
} catch (e) {
console.log("Server nicht erreichbar.");
}
}
2018-06-11 18:15:21 +02:00
//<!--Register-->
document.getElementById('btnCreate').addEventListener("click" , async (event) => {
const formData = new FormData(document.getElementById('create-form'));
try {
const response = await fetch('php/signin.php', {
method: 'post',
body: formData
});
} catch (e) {
console.log("Abschicken der Daten fehlerhaft!");
}
})
//<!--Login-->
document.getElementById('btnLogin').addEventListener("click" , async (event) => {
event.preventDefault();
// if (document.getElementById('btnLogin') === "Login") {
const formData = new FormData(document.getElementById('login-form'));
try {
const response = await fetch('php/signup.php', {
method: 'post',
body: formData
});
const jsonData = await response.json();
if (typeof jsonData.error !== 'undefined') {
console.log(jsonData);
document.getElementById('login-status').innerHTML = jsonData.error.fontcolor("red");
} else {
console.log(jsonData);
if (jsonData == 'true') {
document.getElementById('toggle-login').innerHTML = "Logout";
document.getElementById('btnLogin').innerHTML = "Logout";
document.getElementById('exampleModalLabel').innerHTML = "Logout";
document.getElementById('login-status').innerHTML = "Erfolgreich eingeloggt";
}
else {
document.getElementById('toggle-login').innerHTML = "Login";
document.getElementById('btnLogin').innerHTML = "Login";
document.getElementById('exampleModalLabel').innerHTML = "Login";
document.getElementById('login-status').innerHTML = "Erfolgreich ausgeloggt";
}
// location.reload();
}
} catch (e) {
console.log("Login Fehler");
}
// }
})