// calc.php
<script type="text/javascript">
/* <![CDATA[ */
$(document).ready(function(){
$('#calc').click(function(){
var one = $('input[name="one"]').val();
var two = $('input[name="two"]').val();
var oper = $('select[name="oper"]').val();
$.ajax({
url: 'result.php',
data: {one:one,two:two,oper:oper},
success: function (data) {
$('#result').html(data);
$('#result').attr('disabled', false);
},
dataType: "html"
});
});
});
/* ]]> */
</script>
<input name="one" style="width: 50px;" type="text" />
<select style="width: 50px;" name="oper">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input name="two" style="width: 50px;" type="text" />
<input type="submit" value="Считать" name="calc" id="calc" />
<div id="result">
<!-- AJAX -->
</div>
// result.php
<?php
$operator = $_GET['oper'];
#file_put_contents('log.txt', $one . $operator . $two . PHP_EOL, FILE_APPEND | LOCK_EX);
switch($operator){
case '+':
$result = $one + $two; break;
case '-':
$result = $one - $two; break;
case '*':
$result = $one * $two; break;
case '/':
if($two == 0)
die('Делить на Ноль нельзя');
else
$result = $one / $two;
break;
default:
return false;
}
echo '<b>Результат:' . $result . '</b>';