当我在Firefox中打开控制台时,Console.log(result)显示未定义。返回的json出问题了吗?

这是我的脚本:

function load_contents(track_page) {
    $('#loading').show();
    $.ajax({
        url:'<?php echo base_url('gallery/load_design');?>',
        type:'GET',
        dataType:'json',
        success:function(result) {
            console.log(result);
            alert("success");
        },
        error:function(result) {
            console.log(result);
            alert("failed");
        }
    });
}


我的控制器:

public function load_design() {
    $this->load->model('design');
    $this->load-model('profile');

    $user_id = $this->profile->retrieve_userid();

    $result = $this->design->load_gallery($user_id->id);

    header('Content-Type: application/json');
    echo json_encode($result);
}


我的模特:

function load_gallery($user_id) {
    $data = array();

    $query = $this->db->query("SELECT * from designs WHERE user_id = '".$user_id."' LIMIT 9");
    return $query->result();
}

最佳答案

尝试这个..

控制者

public function load_design()
{
    $this->load->model(array('design','profile'));

    $user_id = $this->profile->retrieve_userid();

    $result = $this->design->load_gallery($user_id->id);

    header('Content-Type: application/json');
    echo json_encode($result);
}


模型:

function load_gallery($user_id)
    {
        $data = array();

        $this->db->where('user_id',$user_id);
        $query = $this->db->get('designs',9,0);
        return $query->result_array();
    }

09-07 13:03