-
Notifications
You must be signed in to change notification settings - Fork 18
/
echo.html
76 lines (60 loc) · 2.28 KB
/
echo.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
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap-theme.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
</head>
<body>
<div class='container' style='margin-top:50px;'>
<div class="input-group input-group-lg">
<input type='text' class='form-control' placeholder='echo [ { "hello": [ "world", "!" ] } ]' aria-describedby='sizing-addon1' id='input'>
<span class='input-group-btn'>
<button type='button' class='btn' id='submit'>execute</button>
</span>
</div>
<div>
<pre id='output'></pre>
</div>
</div>
<script>
$(document).ready(function() {
var id = 0,
$input = $('#input'),
$output = $('#output')
;
function render(data) {
$output.append('<div>Ok [' + data.id + ']' + JSON.stringify(data) + '</div>');
}
function render_error(data, stat, xhr) {
var stat = data.status;
$output.append('<div> Failed [' + stat + '] ' + data.responseText + '</div>');
}
$("#submit").click(function(e) {
e.preventDefault();
var input_text = $input.val();
var method = input_text.substring(0, input_text.indexOf("[")),
params = input_text.substring(input_text.indexOf("["),
input_text.lenght);
try {
var request = {
method: method.replace(/ /g,''),
id: ++id,
params: JSON.parse(params)
};
$.ajax({ type: 'POST',
contentType: 'application/json; charset=utf-8',
dataType: 'json',
url: 'echo',
data: JSON.stringify(request),
success: render,
error: render_error });
} catch (e) {
$output.append('<div>Error: ' + e + '</div>');
}
});
});
</script>
</body>
</html>