dqenv99518 2017-01-16 21:31
浏览 125

Codeigniter和AJAX console.log(结果)显示未定义

Console.log(result) shows undefined when I open my console in firefox. Is there something wrong with the returned json?

Here is my script:

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");
        }
    });
}

My controller:

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);
}

My model:

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

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

3条回答 默认 最新

  • dongshanyan0322 2017-01-17 02:23
    关注

    Try this..

    Controller

    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);
    }
    

    Model:

    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();
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 求用stm32f103c6t6在lcd1206上显示Door is open和password:
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类