internetprogrammierung/frontend/js/contentloader.js

66 lines
1.9 KiB
JavaScript
Raw Permalink 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();
setActiveNav();
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();
2018-06-18 19:10:54 +02:00
var genTan = document.getElementById('genTan');
genTan.innerHTML = "Das ist deine neue friendsTAN: " + `${jsonFirstFetch.html}`;
2018-05-26 14:33:15 +02:00
} 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-18 19:34:17 +02:00
alert(jsonData);
2018-06-13 19:46:32 +02:00
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() : '';
}
function setActiveNav(){
if(window.location.href.indexOf("?") >= 0){
if(window.location.href.indexOf("page=home") >= 0){
$("#navItemHome").addClass('active');
} else if (window.location.href.indexOf("page=newEntry") >= 0){
$("#navItemEntry").addClass('active');
} else if (window.location.href.indexOf("page=myFriendsBook") >= 0){
$("#navItemDashboard").addClass('active');
} else if (window.location.href.indexOf("page=newEntry") >= 0){
$("#navItemEntry").addClass('active');
}
} else {
$("#navItemHome").addClass('active');
}
}