Write the interface, just to let the mobile side, Web side, or PC client call.
We write an interface that returns the JSON format, the function is about arithmetic.
<?php
Header (' Content-type:application/json ');
$operator = $_get[' operator ');
$first = $_get[' first ');
$second = $_get[' second ');
if ($operator = = ' Jia ') {//addition
$result = $first + $second;
}
else if ($operator = = ' Jian ') {//subtraction
$result = $first-$second;
}
else if ($operator = = ' Cheng ') {//multiplication
$result = $first * $second;
}
else{//Division
$result = $first/$second;
}
$result = Array (' res ' = = $result, ' status ' =>1);
echo Json_encode ($result);//return JSON data format
?>
<! DOCTYPE html>
<meta charset= ' Utf-8 ' >
<script></script>
<center>
<input type= ' text ' name= ' first ' id= ' first ' >
<input type= ' text ' name= ' second ' id= ' second ' >
<button value= ' Jia ' > Additions </button>
<div id= ' Jia ' ></div>
<button value= ' jian ' > Subtraction </button>
<div id= ' Jian ' ></div>
<button value= ' Cheng ' > multiplication </button>
<div id= ' Cheng ' ></div>
<button value= ' chu ' > Division </button>
<div id= ' Chu ' ></div>
</center>
<script src= ' jquery.js ' ></script>
<script>
$ (function () {
$ (' button '). Click (function () {
var first = $ (' #first '). Val ();
var second = $ (' #second '). Val ();
var operator = $ (this). Val ();
var area = operator;
var query = ' http://localhost/api.php/? ' + ' first= ' +first+ ' &second= ' +second+ ' &operator= ' +operator;
$.get (query, ", function (data,st) {$.get (We want to enter the Urlget string, the parameters are left blank, callback)
$ (' # ' +area). Text (data.res); The button to which the operation is pressed, it is necessary to assign a value in that area
});
});
});
</script>
There is no simple brain with violent Ajax. Get access API