-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
60 lines (49 loc) · 1.47 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<title>service-turtle</title>
</head>
<body>
<h1>service-turtle</h1>
<div>
<button id="get">GET request</button>
<button id="post">POST request</button>
</div>
<script src="node_modules/console-log-div/console-log-div.js"></script>
<script>
function fetch(method, url) {
var request = new XMLHttpRequest();
request.open(method, url, true);
request.onload = function() {
if (request.status >= 200 && request.status < 400){
console.log('response from', url, request.status, request.responseText);
} else {
// We reached our target server, but it returned an error
console.error('some error', url, request.responseText);
}
};
request.onerror = function() {
// There was a connection error of some sort
console.error('error', url, request.responseText);
};
request.send();
}
function onButtonClick(method) {
console.log(method, 'button clicked');
fetch(method, '/some/url');
}
document.addEventListener('DOMContentLoaded', function() {
document.querySelector('#get').addEventListener('click',
onButtonClick.bind(null, 'GET'));
document.querySelector('#post').addEventListener('click',
onButtonClick.bind(null, 'POST'));
});
</script>
<script>
var serviceTurtleConfig = {
scope: '/'
};
</script>
<script src="turtle.js"></script>
</body>
</html>