-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
66 lines (61 loc) · 1.51 KB
/
test.php
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
<?php
/**
* Created by IntelliJ IDEA.
* User: LR050891
* Date: 16-Mar-17
* Time: 7:59 PM
*/
//https://plot.ly/javascript/line-charts/
?>
<script src="js/main.js"></script>
<div id="tester" onclick="fetch1()" style="width:600px;height:250px;">dff</div>
<script>
function fetchdata(){
console.log("asd");
getJSON("https://api.thingspeak.com/channels/258210/feeds.json?api_key=RAH5AK4OKTMV3Y3F",
function(err, data) {
if (err != null) {
alert("Something went wrong: " + err);
}
else
{
var len=data.feeds.length;
//alert(len);
var i;
var text="";
console.log(len);
for( i=0;i<len;i++)
{
text += data.feeds[i].field1 + "<br>";
}
// document.getElementById("tester").innerHTML = text;
var te=data.feeds[len-1].field1;
document.getElementById("tester").innerHTML = te;
}
});
repeater = setTimeout(fetch, 1000);
}
function fetch1()
{
fetch();
}
var getJSON = function(url, callback)
{
var xhr = new XMLHttpRequest();
xhr.open("get", url, true);
xhr.responseType = "json";
xhr.onload = function()
{
var status = xhr.status;
if (status == 200)
{
callback(null, xhr.response);
}
else
{
callback(status);
}
};
xhr.send();
};
</script>