internetprogrammierung/js/contentloader.js
2018-06-17 23:24:47 +02:00

47 lines
1.3 KiB
JavaScript

window.addEventListener('load', async () => {
console.log("Seite geladen");
//getNewUniqueLink();
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
})
async function getNewUniqueLink() {
const phpSessionForm = new FormData();
phpSessionForm.append("phpSession", PHPSESSIONUSER);
try {
var firstFetch = await fetch('php/generateLink.php', {
method: 'post',
body: phpSessionForm
});
var jsonFirstFetch = await firstFetch.json();
var content = document.getElementById('content');
content.innerHTML = `${jsonFirstFetch.html}`;
} catch (e) {
console.log("Server nicht erreichbar.");
}
}
//<!--Register-->
document.getElementById('btnCreate').addEventListener("click" , async (event) => {
event.preventDefault();
const formData = new FormData(document.getElementById('create-form'));
try {
const response = await fetch('php/signup.php', {
method: 'post',
body: formData
});
const jsonData = await response.json();
console.log(jsonData);
} catch (e) {
console.log("Abschicken der Daten fehlerhaft!");
}
})
function getCookieValue(a) {
var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
}