-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
74 lines (64 loc) · 2.39 KB
/
index.html
File metadata and controls
74 lines (64 loc) · 2.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<html>
<head>
<title>Página de coleta de dados do AlertaBlu</title>
<script>
// https://www.w3schools.com/xml/ajax_intro.asp
// https://www.w3schools.com/jsref/met_document_getelementbyid.asp
// https://www.w3schools.com/jsref/prop_node_firstchild.asp
// https://www.w3schools.com/jsref/met_node_removechild.asp
// https://www.w3schools.com/js/js_json_parse.asp
// https://www.w3schools.com/js/js_object_es5.asp
// https://www.w3schools.com/js/js_loop_for.asp
// https://www.w3schools.com/jsref/met_document_createelement.asp
// https://www.w3schools.com/js/js_datatypes.asp
// https://www.w3schools.com/jsref/met_win_setinterval.asp
function loadTable() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var table = document.getElementById("tableValues");
while( table.firstChild ){
table.removeChild( table.firstChild );
}
var data = JSON.parse( this.responseText );
var keys = Object.keys( data );
for( var k in keys ){
var tr = document.createElement( 'tr' );
var name = keys[k];
var type = typeof data[ keys[k] ];
var title = tr.appendChild( document.createElement('td') );
//title.innerHTML = `<b>${keys[k]}</b>`;
title.innerHTML = '<b>'+keys[k]+'</b>';
if( type == 'object' ){
for( var j in data[ keys[k] ] ){
var td = document.createElement( 'td' );
td.innerText = data[ keys[k] ][j];
if( keys[k] == 'condicao_do_tempo_img' ){
td.innerHTML = '<img src="http://alertablu.cob.sc.gov.br/static/img/previsao/' + td.innerText + '"/>';
}
tr.appendChild( td );
}
}
else if( type == 'string' ){
var td = document.createElement( 'td' );
td.innerText = data[ keys[k] ];
tr.appendChild( td );
}
table.appendChild( tr );
}
}
};
xhttp.open( "GET", "http://www.everton.mat.br/alertablu/data.php?option=all", true );
xhttp.send();
}
window.onload = function(){
loadTable();
setInterval( loadTable, 60000 );
}
</script>
</head>
<body>
<h1 align="center">Página de coleta de dados do AlertaBlu</h1>
<table align="center" border="1" id="tableValues"></table>
</body>
</html>