-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
80 lines (78 loc) · 2.2 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
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Calculator</title>
<style>
body {
width: 600px;
margin: auto;
}
#header {
background-color: #ccc;
padding-left: 30px;
margin: 0;
}
#header h1 {
text-align: center;
margin: 0;
}
#header ul {
padding-left: 50px;
}
#calc {
text-align: center;
width: 100%;
}
#calc .wideInput {
width: 90%;
font-size: 1.5em;
}
</style>
</head>
<body>
<div id="header">
<h1>Calculator</h1>
<p>This is the simplest AJAX calculator. Now it performs following operations:
<ul>
<li>Addition (+)</li>
<li>Subtraction (-)</li>
<li>Multiplication (*)</li>
<li>Division (/)</li>
<li>Power (^)</li>
</ul>
The expression could have groping operators by parentheses.
</p>
</div>
<form action="#" method="POST" id="calc">
<input type="text" name="expr" placeholder="Input expression... " class="wideInput" id="calcInput">
<p><input type="submit" value="Calculate!"> </p>
</form>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
(function($){
var form = $('#calc'),
input = form.find('#calcInput'),
callback = $('callback');
form.on('submit', function( e ){
e.preventDefault();
var value = input.val();
$.ajax({
//url is hardcoded to help make cross browsers requests on saved page index.html
url: 'http://vladimir.v.petukhov.vds.free-th.ru/calc_api.php',
method: 'POST',
jsonp: 'callback',
dataType: 'jsonp',
data: {expr: value},
success: function(data)
{
if ( data.msg ) {
input.val( data.msg );
}
}
});
});
})(jQuery);
</script>
</body>
</html>