blob: d7f3945f2edb412e85579317817d5b10d6f2b72d [file] [log] [blame]
Roger Meierf04cfca2010-10-15 19:24:32 +00001<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2<!--
3 Licensed to the Apache Software Foundation (ASF) under one
4 or more contributor license agreements. See the NOTICE file
5 distributed with this work for additional information
6 regarding copyright ownership. The ASF licenses this file
7 to you under the Apache License, Version 2.0 (the
8 "License"); you may not use this file except in compliance
9 with the License. You may obtain a copy of the License at
10
11 http://www.apache.org/licenses/LICENSE-2.0
12
13 Unless required by applicable law or agreed to in writing,
14 software distributed under the License is distributed on an
15 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 KIND, either express or implied. See the License for the
17 specific language governing permissions and limitations
18 under the License.
19-->
20<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
21<head>
22 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
23 <title>Thrift Javascript Bindings - Tutorial Example</title>
24
Roger Meierea4600b2013-09-21 08:47:21 +020025 <script src="../../lib/js/src/thrift.js" type="text/javascript"></script>
Roger Meierfa899322012-10-22 19:27:38 +000026 <script src="gen-js/tutorial_types.js" type="text/javascript"></script>
27 <script src="gen-js/shared_types.js" type="text/javascript"></script>
28 <script src="gen-js/SharedService.js" type="text/javascript"></script>
29 <script src="gen-js/Calculator.js" type="text/javascript"></script>
Roger Meierf04cfca2010-10-15 19:24:32 +000030
31 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
32
33
34 <script type="text/javascript" charset="utf-8">
35 //<![CDATA[
36 $(document).ready(function(){
37 // remove pseudo child required for valid xhtml strict
38 $("#op").children().remove();
39 // add operations to it's dropdown menu
40 $.each(Operation, function(key, value) {
41 $('#op').append($("<option></option>").attr("value",value).text(key));
42 });
43
44 $('table.calculator').attr('width', 500);
45 });
46
47 function calc() {
48 var transport = new Thrift.Transport("/thrift/service/tutorial/");
49 var protocol = new Thrift.Protocol(transport);
50 var client = new CalculatorClient(protocol);
51
Roger Meier443ced02014-03-26 23:23:37 +010052 var work = new Work();
Roger Meierf04cfca2010-10-15 19:24:32 +000053 work.num1 = $("#num1").val();
54 work.num2 = $("#num2").val();
55 work.op = $("#op").val();
56
57 try {
58 result = client.calculate(1, work);
59 $('#result').val(result);
60 $('#result').css('color', 'black');
61 } catch(ouch){
62 $('#result').val(ouch.why);
63 $('#result').css('color', 'red');
64 }
65 }
66
67 function auto_calc() {
68 if ($('#autoupdate:checked').val() !== undefined) {
69 calc();
70 }
71 }
72 //]]>
73 </script>
74
75</head>
76<body>
77 <h2>Thrift Javascript Bindings</h2>
78 <form action="">
79 <table class="calculator">
80 <tr>
81 <td>num1</td>
82 <td><input type="text" id="num1" value="20" onkeyup="javascript:auto_calc();"/></td>
83 </tr>
84 <tr>
85 <td>Operation</td>
86 <td><select id="op" size="1" onchange="javascript:auto_calc();"><option></option></select></td>
87 </tr>
88 <tr>
89 <td>num2</td>
90 <td><input type="text" id="num2" value="5" onkeyup="javascript:auto_calc();"/></td></tr>
91 <tr>
92 <td>result</td>
93 <td><input type="text" id="result" value=""/></td></tr>
94 <tr>
95 <td><input type="checkbox" id="autoupdate" checked="checked"/>autoupdate</td>
96 <td><input type="button" id="calculate" value="calculate" onclick="javascript:calc();"/></td>
97 </tr>
98 </table>
99 </form>
100
Roger Meier565517a2013-03-22 21:08:39 +0100101 <p>This Java Script example uses <a href="https://git-wip-us.apache.org/repos/asf?p=thrift.git;a=blob;f=tutorial/tutorial.thrift;hb=HEAD">tutorial.thrift</a> and a Thrift server using JSON protocol and HTTP transport.
Roger Meierf04cfca2010-10-15 19:24:32 +0000102 </p>
103 <p>
104 <a href="http://validator.w3.org/check/referer"><img
105 src="http://www.w3.org/Icons/valid-xhtml10"
106 alt="Valid XHTML 1.0!" height="31" width="88" /></a>
107 </p>
108</body>
109</html>