doudou0111 2018-03-07 03:44 采纳率: 0%
浏览 26
已采纳

如何将数据json从ajax回显到modal js codeigniter?

i want to display data from ajax into model show with echo php, i have made ajax and have working no errors.

this is my model

public function detail($id_branch) {
    $this->db->select('TR_BRANCH.*');
    $this->db->from('TR_BRANCH');
    $this->db->where('BRANCH_ID', $id_branch);
    $query = $this->db->get();
    return $query->result();

}

my controller

Public function detail($id_branch){
    $data = $this->main_model->detail($id_branch);
    echo json_encode($data);
    $this->load->view('template/pages/home_index', $data);
}

my ajax

function coba(id_branch) {
    $('#placeholder').hide();

    $('#placeholder').show(function(){

        $.ajax({
            url:"<?php echo base_url() ?>home/detail/" + id_branch,
            success(res){
                // alert(id_branch)
            }
        })


    });

}

my view

<div id="placeholder">
<div class="row">
    <div class="panel panel-default">
        <div class="panel-heading clearfix">
         <p><?php echo $data->DISPLAY_NAME; ?></p>
        </div>
    </div>
</div>

if i

<?php echo $data->DISPLAY_NAME; ?> 

in my modal, i'm getting error like Undefined variable: data. result data json_encode already appear in network based id_branch. how to fix it? pls help

  • 写回答

3条回答 默认 最新

  • doubi6898 2018-03-07 05:25
    关注

    As you are getting DISPLAY_NAME in Ajax request, so you cannot use $data->DISPLAY_NAME,

    You need to give id to p tag & update its value in ajax success method

    <p id="displayName"></p>
    
    
    success(res) 
    {
        // alert(id_branch)
         $("#displayName").html(Read Value from res data);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 unity腾讯云对象存储机型适配
  • ¥15 求全国交通咨询模拟代码,要求如下,可以完全在dev c++运行
  • ¥15 根据要求修改程序编码
  • ¥15 用 Python 做一个用 Excel 表导入的答题系统
  • ¥15 使用微信开发者工具实现一个“婚博会”小程序
  • ¥15 ros的rviz仿真机器人
  • ¥15 关于#linux#的问题(输入输出错误):出现这个界面接着我重新装系统,又让修电脑的师傅帮我扫描硬盘(没有问题)用着用着又卡死(相关搜索:固态硬盘)
  • ¥15 cv::resize不同线程时间不同
  • ¥15 web课程,怎么做啊😭没好好听课 根本不知道怎么下手
  • ¥15 做一个关于单片机的比较难的代码,然后搞一个PPT进行解释