<!DOCTYPE html>

<meta charset="UTF-8">

<title>getJSON示例</title>

</head>

<body class="bg-orange">

<pre>

后端的PHP代码:

public function tt1(){

    $t1 = I('t1');

    $t2 = I('t2');

    $this->ajaxReturn('t1='.$t1.',t2='.$t2, 'success', '1');

}

</pre>

    t1:<input type="text" id="t1" />

    t2:<input type="text" id="t2" />

    <input type="button" id="s" value="提交" />

</body>

<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>

<script>

$(function(){

    $('#s').on('click',function(){        

        var t1 = $('#t1').val();

        var t2 = $('#t2').val();

        //$.getJSON(url,data,success(data,status,xhr))

        var send = {"t1":t1, "t2":t2};

        $.getJSON('{:U('Index/tt1')}', send, function(data,status,xhr){

            alert(data.status +"\r\n"+data.data);

        });

    })

})

</script>

03-14 16:30