-
Notifications
You must be signed in to change notification settings - Fork 5
/
basic_operations.html
54 lines (53 loc) · 1.42 KB
/
basic_operations.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
<html>
<head>
<script
src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous">
</script>
<script type="text/javascript">
var server = "http://127.0.0.1:5000";
var op_num = {'sum':[3,4]};
function update_var()
{
var n1 = parseFloat($("#n1").val());
var n2 = parseFloat($("#n2").val());
op_num['sum']=[n1,n2];
}
$( function() {
$( "#sum" ).click(function() {
var appdir='/sum';
var send_msg = "<p>Sending numbers</p>";
var received_msg = "<p>Result returned</p>";
update_var();
console.log(send_msg);
$('#message').html(send_msg);
$.ajax({
type: "POST",
url:server+appdir,
data: JSON.stringify(op_num),
dataType: 'json'
}).done(function(data) {
console.log(data);
$('#n3').val(data['sum']);
$('#message').html(received_msg+data['msg']);
});
});
});
</script>
</head>
<body>
<div>
<div>
<label>N1:</label><input id="n1" type="number" value="3" max="300" min="-300"/><br/>
<label>N2:</label><input id="n2" type="number" value="2" max="300" min="-300"/><br/>
<label>Result:</label><input id="n3" type="number"/><br/>
</div>
<div id="sum" style="background-color:gray; width:100px; color:white;">
Click to sum numbers
</div>
<div id="message">
</div>
</div>
</body>
</html>