码迷,mamicode.com
首页 > Web开发 > 详细

夺命雷公狗jquery---54通过ajax的底层实现返回json格式的数据

时间:2015-10-30 09:18:53      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

<!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);

 

夺命雷公狗jquery---54通过ajax的底层实现返回json格式的数据

标签:

原文地址:http://www.cnblogs.com/leigood/p/4922307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!