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

jquery - ThinkPHP ajaxReturn multiple 2D arrays - Stack Overflow

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-08-10 09:07:24
Original
1162 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

$.get(url, {}, function(d){
    if ($.isArray(d)) {
        $.each(d, function(i, v){
            $('.demo').append(v);
        })
    }
}, 'json');
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:
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template