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

jquery - ThinkPHP ajaxReturn multiple 2D arrays - Stack Overflow

WBOY
Release: 2016-08-10 09:07:24
Original
1136 people have browsed it

<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>
Copy after login
Copy after login
<code> print_r($data);

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

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>
Copy after login
Copy after login
<code> print_r($data);

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

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>
Copy after login

<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>
Copy after login
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template