-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
86 lines (72 loc) · 2.12 KB
/
index.html
File metadata and controls
86 lines (72 loc) · 2.12 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
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Merge Page</title>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
</head>
<body>
<script type="text/javascript">
function loadDatabase(){
$.ajax({ //query the database
type: "GET",
url: "https://game-of-life-backend.eu-de.mybluemix.net/v2/gol",
//data: 'page='+url, //with the page number as a parameter
dataType: "json", //expect html to be returned
success: function(msg){
console.log(msg)
var html = ""
for(var i=0; i<msg.length; ++i){
html += ("<b>"+msg[i].title+"</b>")
html += ("<p>"+msg[i].body+"</p>")
}
$('#database').html(html); //load the returned html into pageContet
}
});
}
$(document).ready(function(){
$("#msgid").html("This is Hello World by JQuery");
$.ajax({ //play gol
type: "GET",
url: "https://eu-de.functions.cloud.ibm.com/api/v1/web/pohl%40de.ibm.com_dev/default/helloJava.json",
dataType: "json", //expect html to be returned
success: function(msg){
var board = msg.grid;
console.log(board)
var niceBoard = "";
for (var i = 0; i < board.length; i++) {
for (var j = 0; j < board[0].length; j++) {
niceBoard += board[i][j] ? "." : "*";
}
niceBoard += "<br/>"
}
$('#gol').html(niceBoard); //load the returned html into pageContet
}
});
loadDatabase();
});
function writeToTheDatabase(){
var data = {
"body": "my body that is very special",
"title": "This is my new written title"
};
$.ajax({ //query the database
type: "POST",
url: "https://game-of-life-backend.eu-de.mybluemix.net/v2/gol",
contentType: 'application/json; charset=utf-8',
dataType: 'json',
data: JSON.stringify(data),
success: loadDatabase
});
}
</script>
Here we will merge two applications
<div id="gol">
</div>
<hr></hr>
Here goes the database stuff
<p><button onclick="writeToTheDatabase()">click</button></p>
<div id="database">
</div>
</body>
</html>