<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="js/jquery.js"></script> <script> $(function(){ $(‘#btnok‘).bind(‘click‘,function(){ $.ajax({ type:‘post‘, url:‘ajax3.php‘, data:‘first=100&second=20‘, dataType:‘json‘, success:function(msg){ alert(msg.jia+‘--‘+msg.jian+‘--‘+msg.cheng+‘--‘+msg.chu); } }); }); }); </script> </head> <body> <input type="button" id="btnok" value="OK" /> </body> </html>
PHP的代码:
<?php $first = $_POST[‘first‘]; $second = $_POST[‘second‘]; $jia = $first+$second; $jian = $first-$second; $cheng = $first*$second; $chu = $first/$second; $arr = array( ‘jia‘=>$jia, ‘jian‘=>$jian, ‘cheng‘=>$cheng, ‘chu‘=>$chu ); echo json_encode($arr);
时间: 2024-10-24 11:14:37