Commit c4c9ac3b authored by Jogi Hofmüller's avatar Jogi Hofmüller

Add basic frontend functionality

parent 27b218b5
// Javascript for ggv3 frontend
// Copyright GPL v3 institut hofos 2019
var url = 'https://plagi.at:8888/get';
// jquery/ajax version
// function nextgeruecht() {
// $.ajax({
// type: 'GET',
// datatype: 'json',
// url: 'https://localhost:8888/get',
// success: function(data, status, jqXHR) {
// result = JSON.parse(data);
// $('#geruecht').html(result.payload);
// console.log('Debug: viewing geruecht')
// },
// error: function(jqXHR, status) {
// $('#geruecht').html('Sorry, ein Fehler, kein Gerücht');
// console.log('error');
// }
// })
// return false;
// }
var hostname = 'localhost'
var geturl = 'https://'+ hostname + ':8888/get';
var addurl = 'https://'+ hostname + ':8888/add';
function nextgeruecht() {
fetch(url, {
credentials: 'omit'
fetch(geturl, {
method: 'GET',
credentials: 'include',
mode: 'cors'
})
.then(function(response) {
if (response.ok) {
......@@ -41,39 +26,31 @@ function nextgeruecht() {
})
}
function addgeruecht() {
var payload = document.getElementById('newgeruecht').value;
fetch(addurl, {
credentials: 'include',
method: 'PUT',
mode: 'cors',
body: JSON.stringify(payload),
headers: {
'Content-Type': 'application/json; charset=utf8'
}
})
.then(function(response) {
if (response.ok) {
return response.json();
}
throw new Error('Network error (response not ok)');
})
.then(function(data) {
document.getElementById('geruecht').innerHTML = data.message;
})
.catch(function(error) {
document.getElementById('geruecht').innerHTML = 'API Fehler: ' + error;
console.log('API error: ' + error);
})
}
window.onload = function() {
nextgeruecht();
};
// function addgeruecht() {
// var obj = new Object();
// obj.value = $('#newgeruecht').val();
// obj.state = 0;
// obj.type = 'geruecht';
// $.ajax({
// type: 'POST',
// datatype: 'json',
// url: 'https://localhost:8888/add',
// data: JSON.stringify(obj),
// contentType: 'application/json; charset=utf-8',
// crossdomain: true,
// success: function(response, status, jqXHR) {
// result = JSON.parse(response);
// $('#geruecht').removeClass('alert-danger').addClass('alert-success');
// $('#geruecht').html(result.message);
// console.log('Debug: added something')
// },
// error: function(jqXHR, status) {
// $('#geruecht').removeClass('alert-success').addClass('alert-danger');
// $('#geruecht').html('an error occured');
// console.log('error');
// }
// })
// return false;
// }
// $('#geruecht').on('click', next);
// $('#next').on('click', next);
// // $('#addgeruecht').on('submit', addgeruecht);
// $(document).ready(next);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment