Home  >  Article  >  Backend Development  >  jquery - ThinkPHP ajaxReturn multiple 2D arrays - Stack Overflow

jquery - ThinkPHP ajaxReturn multiple 2D arrays - Stack Overflow

WBOY
WBOYOriginal
2016-08-10 09:07:241059browse

<code>public function autorun(){
        $uid = session('uid');
        $map['pid'] = $uid;
        $User = M('land');
        $data = $User->field('land')->where($map)->select();

        print_r($data);
        //$this -> ajaxReturn($data);
    }
 </code>
<code> print_r($data);

Array ( [0] => Array ( [land] => 1 ) [1] => Array ( [land] => 2 ) ) //可能会有更多数据</code>

Please tell me how to write ajaxReturn in the brackets. In the past, it was a one-dimensional array and it was one. This won't happen. What the frontend receives is the value in [land]. If multiple values ​​are received, how does jquery separate these values.

Reply content:

<code>public function autorun(){
        $uid = session('uid');
        $map['pid'] = $uid;
        $User = M('land');
        $data = $User->field('land')->where($map)->select();

        print_r($data);
        //$this -> ajaxReturn($data);
    }
 </code>
<code> print_r($data);

Array ( [0] => Array ( [land] => 1 ) [1] => Array ( [land] => 2 ) ) //可能会有更多数据</code>

Please tell me how to write ajaxReturn in the brackets. In the past, it was always a one-dimensional array and it was one. This won't happen. What the frontend receives is the value in [land]. If multiple values ​​are received, how can jquery separate these values.

jquery is as follows

<code class="javascript">$.get(url, {}, function(d){
    if ($.isArray(d)) {
        $.each(d, function(i, v){
            $('.demo').append(v);
        })
    }
}, 'json');</code>

<code> $.ajax(  
    url: url,
    type: "get",
    dataType: "json",
    success:function(data) {
         for(var i in data){
             var obj = data[i];
             console.log(obj.land);
         }
    }  
 );</code>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn