|
10 | 10 | <body> |
11 | 11 | <div class='container' style='margin-top:50px;'> |
12 | 12 | <div class="input-group input-group-lg"> |
13 | | - <input type='text' class='form-control' placeholder='{}' aria-describedby='sizing-addon1' id='input'> |
| 13 | + <input type='text' class='form-control' placeholder='echo [ { "hello": [ "world", "!" ] } ]' aria-describedby='sizing-addon1' id='input'> |
14 | 14 | <span class='input-group-btn'> |
15 | 15 | <button type='button' class='btn' id='submit'>execute</button> |
16 | 16 | </span> |
|
23 | 23 | <script> |
24 | 24 | $(document).ready(function() { |
25 | 25 |
|
26 | | - var id = 0; |
27 | | - var $out = $('#output'); |
| 26 | + var id = 0, |
| 27 | + $input = $('#input'), |
| 28 | + $output = $('#output') |
| 29 | + ; |
28 | 30 |
|
29 | 31 | function render(data) { |
30 | | - $out.append('<div>[' + data.id + ']' + JSON.stringify(data) + '</div>'); |
| 32 | + $output.append('<div>Ok [' + data.id + ']' + JSON.stringify(data) + '</div>'); |
31 | 33 | } |
32 | 34 |
|
33 | 35 | function render_error(data, stat, xhr) { |
34 | | - if (data.status && |
35 | | - (data.status === 502 || data.status == 500)) |
36 | | - { |
37 | | - $out.append('<div>tarantool backend failure</div>'); |
38 | | - } |
| 36 | + var stat = data.status; |
| 37 | + $output.append('<div> Failed [' + stat + '] ' + data.responseText + '</div>'); |
39 | 38 | } |
40 | 39 |
|
41 | | - $("#submit").click(function() { |
| 40 | + $("#submit").click(function(e) { |
| 41 | + |
| 42 | + e.preventDefault(); |
| 43 | + |
| 44 | + var input_text = $input.val(); |
| 45 | + |
| 46 | + var method = input_text.substring(0, input_text.indexOf("[")), |
| 47 | + params = input_text.substring(input_text.indexOf("["), |
| 48 | + input_text.lenght); |
42 | 49 |
|
43 | 50 | try { |
44 | | - var $input = $('#input'); |
45 | | - var call = JSON.stringify({ |
46 | | - method: 'call', |
47 | | - params: ['echo', JSON.parse($input.val())], |
48 | | - id: ++id |
49 | | - }); |
| 51 | + |
| 52 | + var request = { |
| 53 | + method: method.replace(/ /g,''), |
| 54 | + id: ++id, |
| 55 | + params: JSON.parse(params) |
| 56 | + }; |
50 | 57 |
|
51 | 58 | $.ajax({ type: 'POST', |
52 | 59 | contentType: 'application/json; charset=utf-8', |
53 | 60 | dataType: 'json', |
54 | | - url: 'tnt', |
55 | | - data: call, |
| 61 | + url: 'echo', |
| 62 | + data: JSON.stringify(request), |
56 | 63 | success: render, |
57 | | - error: render_error}); |
| 64 | + error: render_error }); |
58 | 65 |
|
59 | 66 | } catch (e) { |
60 | | - $out.append('<div> Error:' + e + '</div>'); |
| 67 | + $output.append('<div>Error: ' + e + '</div>'); |
61 | 68 | } |
| 69 | + |
62 | 70 | }); |
63 | 71 |
|
64 | 72 | }); |
|
0 commit comments