jquery .ajax

view:

    $(document).ready(function() {
        var ss="asdff";
        $(".check").click(function(){
            alert("OK");    
            $.ajax({
            type:'get',
            url:'<?php echo URL::base(true)?>purchasepay/finance/purchasepay/payaction',
            async:false,
            data:{pro:ss,needpay:ss},
            success:function(data)
            {
                alert(data);
            },
            error:function(){
                alert("error");
            }
        });
            });
    });

    

controller:

        $s=$_GET["pro"];
        
        echo json_encode ( $s );      

$.each()

  $.each(data, function(commentIndex, comment){
                               html += '<div class="comment"><h6>' + comment['username']
                                         + ':</h6><p class="para"' + comment['content']
                                         + '</p></div>';
                         });

$.each()函数不同于JQuery对象的each()方法,它是一个全局函数,不操作JQuery对象,而是以一个数组或者对象作为第1个参数,以一个回调函数作为第2个参数。回调函数拥有两个参数:第1个为对象的成员或数组的索引,第2个为对应变量或内容。

原文地址:https://www.cnblogs.com/canbefree/p/3709846.html