function getAllData(){ $.ajax({ type: "GET", url: 'data.db', success: function(ret) { $.each(ret.data, function(i, item) { setSingleData(item); }); } }); } function setSingleData(singleData){ //remove data $( "#" + singleData.seriennummer ).remove(); container = document.getElementById(singleData.activity); entry = document.createElement("div"); $(entry).attr("id",singleData.seriennummer); $(entry).html("Code: " + singleData.produktcode + " SN: " + singleData.seriennummer + ""); container.appendChild(entry); } function showDocument() { $.ajax({ type: "GET", url: 'style.url', success: function(ret) { $('head link.custom').attr('href',ret); } }); /* $.ajax({ type: "GET", url: 'info.json', success: function(ret) { makeGrid(ret.x_amount, ret.y_amount); //set name document.title = ret.document_name; $.ajax({ type: "GET", url: 'frames.json', success: function(ret2) { for (i of ret2.data) { makeFrame(i.lx,i.ly,i.rx,i.ry, i.url, i.callback, i.default, i.showbutton, i.style); } } }); }, error: function() { reason = ''; clearDocument(); } });*/ } function clearDocument() { console.log('rrrr'); $('#languages').addClass('hidden'); $('#nope').removeClass('hidden'); $('#control .added').remove(); $('#content .added').remove(); $('#reason').text(reason); } function init() { es = new EventSource('sse/'); es.onopen = function() { getAllData(); // load }; es.onmessage = function(e) { console.log("Got SSE"); if (e.data == 'new') { reason = ''; showDocument(); } if (e.data == 'reset') { reason = ''; showDocument(); } else{ if(e.data == "update"){ alert("update") } if(e.data != "keepalive" && e.data != "started"){ try { var prdata = JSON.parse(e.data) //alert("LastIf" + prdata.seriennummer) setSingleData(prdata); } catch (e) { } } } }; es.onerror = function() { reason = 'Server down.'; clearDocument(); setTimeout(init, 10000); }; } $(document).ready(function() { init(); });