-
Notifications
You must be signed in to change notification settings - Fork 0
/
hellosparql.html
122 lines (101 loc) · 4.17 KB
/
hellosparql.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<title>Hello World -- SPARQL!</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
<link href="assets/css/bootstrap-glyphicons.css" type="text/css" rel="stylesheet">
<!--[if lt IE 9]>
<script src="assets/js/html5.js"></script>
<![endif]-->
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate" />
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="Expires" content="0" />
<style type="text/css" id="bsCss">
/* override bootstrap styles */
body { padding-top: 50px;}
</style>
</head>
<body>
<div class="container">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Hello World!</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a href="hello.html">HTTP PUT</a></li>
<li><a href="hellopatch.html">HTTP PATCH</a></li>
<li class="active"><a href="hellosparql.html">SPARQL UPDATE</a></li> </ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div>
<h1>Hello World -- SPARQL!</h1>
<div id="counter">
</div>
<hr>
<div>
Use the following code to <strong>write</strong> to your data space via SPARQL:
<pre>
var c = location.origin + '/counter';
var xhr = new XMLHttpRequest();
xhr.open('POST', c, false);
xhr.setRequestHeader('Content-Type',' application/sparql-update');
xhr.send('DELETE DATA { <'+c+'> <'+c+'> "' + counter + '" . }');
xhr.open('POST', c, false);
xhr.setRequestHeader('Content-Type',' application/sparql-update');
xhr.send('INSERT DATA { <'+c+'> <'+c+'> "' + (counter+1) + '" . }');
</pre>
<hr>
Use the following code to <strong>read</strong> from your data space:
<pre>
var c = location.origin + '/counter';
$.getJSON(c , function(data){
if (data[c]) {
counter = parseInt(data[c][c][0]['value']);
}
});
</pre>
<hr>
</div>
</div>
<script type='text/javascript' src="assets/js/jquery.min.js"></script>
<script type='text/javascript' src="assets/js/bootstrap.min.js"></script>
<script>
var init = function() {
// counter URI
var c = location.origin + '/counter';
var counter = 0;
$.getJSON(c , function(data){
// get counter value and increment
if (data[c]) {
counter = parseInt(data[c][c][0]['value']);
}
// update page
$('#counter').append('<p>You are visitor number <strong>' + (counter+1) + '</strong> to this page.</p>');
// write back counter
var xhr = new XMLHttpRequest();
xhr.open('POST', c, false);
xhr.setRequestHeader('Content-Type',' application/sparql-update; charset=UTF-8');
xhr.send('DELETE DATA { <'+c+'> <'+c+'> "' + counter + '" . }');
xhr.open('POST', c, false);
xhr.setRequestHeader('Content-Type',' application/sparql-update; charset=UTF-8');
xhr.send('INSERT DATA { <'+c+'> <'+c+'> "' + (counter+1) + '" . }');
});
}
$(document).ready(init);
</script>
</body>
</html>