internetprogrammierung/js/contentloader.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-05-26 14:33:15 +02:00
window.addEventListener('load', async () => {
console.log("Seite geladen");
2018-06-17 23:05:13 +02:00
//getNewUniqueLink();
document.getElementById('btnCreateTan').addEventListener('click' , async (event) => getNewUniqueLink());
2018-05-26 14:33:15 +02:00
})
async function getNewUniqueLink() {
2018-06-17 23:05:13 +02:00
const phpSessionForm = new FormData();
phpSessionForm.append("phpSession", PHPSESSIONUSER);
2018-05-26 14:33:15 +02:00
try {
2018-06-17 23:05:13 +02:00
var firstFetch = await fetch('php/generateLink.php', {
method: 'post',
body: phpSessionForm
});
2018-05-26 14:33:15 +02:00
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('create-form').addEventListener("submit" , async (event) => {
2018-06-17 23:24:47 +02:00
event.preventDefault();
2018-06-11 18:15:21 +02:00
const formData = new FormData(document.getElementById('create-form'));
try {
const response = await fetch('php/signup.php', {
2018-06-11 18:15:21 +02:00
method: 'post',
body: formData
});
2018-06-13 19:46:32 +02:00
const jsonData = await response.json();
console.log(jsonData);
2018-06-11 18:15:21 +02:00
} catch (e) {
console.log("Abschicken der Daten fehlerhaft!");
}
})
2018-06-17 23:05:13 +02:00
function getCookieValue(a) {
var b = document.cookie.match('(^|;)\\s*' + a + '\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
}