From 37db23a0e8520a6eed5521e5d3129a4b49b9bd3a Mon Sep 17 00:00:00 2001 From: d3m1g0d Date: Sun, 14 Apr 2019 20:38:43 +0200 Subject: [PATCH] Divide and conquer on updateData... --- frontend/frontend.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/frontend/frontend.js b/frontend/frontend.js index 0c15faa..2ef2926 100644 --- a/frontend/frontend.js +++ b/frontend/frontend.js @@ -1,10 +1,19 @@ $('#update').click(updateData); -function updateData () { +// jQuery event binder + +function updateData (obj) { + // download data from backend into obj const url = 'http://' + window.location.hostname + ':5000/data'; - $.get(url, function (data, status) { - $('#debug').text(data); - for (const i in data[0]) { - $('#'+i).text(data[0][i]); - } + // I understand how bad this line looks. Please don't judge me... + $.get(url, function (data, status) { // standard jQuery AJAX + obj = data; }); } + +function applyData (obj, dom) { + // applies data in obj[0] to HTML tags with the obj's key as ID. + // useful mostly for slapping spectrometer JSON into HTML tables. + for (var i in obj[0]) { + $(dom).find('#' + i).text(obj[0][i]); + } +}