-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
81 lines (56 loc) · 1.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<html>
<head>
<style> body { padding: 3em; } </style>
<script src=jquery.js></script>
</head>
<body>
<h1>Test Page</h1>
<b>Enter message values here</b><br>
Construct a message by entering the key/value pairs in this box, one per line.
<textarea id=vals cols=80 rows=8>
m hello!
</textarea>
<input id=sendbtn type=button value="Send"><p>
<b>This is the message actually sent to server</b><br>
<textarea id=msgsent cols=80 rows=8></textarea> <p>
<b>This is the response message from the server</b><br>
<textarea id=msgrcvd cols=80 rows=8></textarea><p>
<script>
apiURL = "http://localhost:50505/api/"
function el(id) { return document.getElementById(id) }
function o2j(o) { return JSON.stringify(o) }
function j2o(j) { return JSON.parse(j) }
function jsondReady() {
var vals = el("vals")
var msgrcvd = el("msgrcvd")
var msgsent = el("msgsent")
var seq = 1;
$("#sendbtn").click(function() {
var lines = vals.value.split("\n"),
msg = {},
line, i, m
msgrcvd.value = ""
msgsent.value = ""
for(i = 0; i < lines.length; i++) {
line = lines[i]
m = line.match(/^([^\s]+) (.*)$/)
if(m) {
msg[m[1]] = m[2]
}
}
msgsent.value = o2j(msg)
jsond.send(msg, function(rmsg) {
msgrcvd.value = o2j(rmsg)
})
})
}
function docReady() {
var d = document, e = d.createElement('script')
e.id = "jsond"
e.async = false
e.src = apiURL
e.onload = jsondReady
d.body.appendChild(e)
}
$(document).ready(docReady)
</script>