-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.html
More file actions
38 lines (36 loc) · 928 Bytes
/
Copy pathindex.html
File metadata and controls
38 lines (36 loc) · 928 Bytes
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<button class="create">Create Game</button>
<button class="join">Join Game</button>
<!--comment-->
<script>
document.querySelector("button.create").onclick = function() {
var name = prompt("Game name?");
if (name) {
var xhr = new XMLHttpRequest();
xhr.open('POST', '/games');
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('game_name=' + name);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
location.href = '/games/' + name;
} else {
alert('Error creating game: ' + xhr.responseText);
}
}
};
}
};
document.querySelector("button.join").onclick = function() {
var name = prompt("Game name?");
if (name) {
location.href = '/games/' + name;
}
};
</script>
</body>
</html>