-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathjsonp-example.html
56 lines (49 loc) · 1.4 KB
/
jsonp-example.html
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
<!DOCTYPE html>
<!-- Example of fetching Eligius data from a remote server -->
<!-- Source can be run/edited via http://jsbin.com/aPUjeCa/6/edit -->
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<meta charset=utf-8 />
<title>Eligius JSONP Tester</title>
<br>
<div style="font-size:23px">
JSONP Fetch Of Eligius Data
</div>
<style id="jsbin-css">
</style>
</head>
<body>
<br><span>Hashrate: </span>
<span id='hashrate'>"uninitialized"</span>
<br><br><span>Status: </span>
<span id='status'>Waiting for click</span>
<br><br>
<button onclick="getData()"; style="font-size:16px;background:lightGreen">Click here to fetch padded JSON at eligius.st</button>
<br><br>
<textarea id='txtbox' rows="10" cols="50">
</textarea>
<script>
var url = "http://eligius.st/~wizkid057/newstats/api.php?cmd=gethashrate&format=jsonp";
function errorHandler(e) {
$("#status").text( e.message );
}
function dataHandler ( jsondata, status, xhr ) {
$("#status" ).text( status );
$("#hashrate").text( jsondata.output.av256.pretty );
$("#txtbox" ).text( JSON.stringify ( jsondata ) );
}
function getData(){
$("#hashrate").text("_________");
$("#status" ).text("Requesting data...");
// here is the actual fetch:
$.ajax({
url: url,
dataType: 'jsonp',
success: dataHandler,
error: errorHandler
});
}
</script>
</body>
</html>