weixin_33674976 2018-08-16 02:05 采纳率: 0%
浏览 9

从JSON编码获取数据

I am using echo json_encode($data); to send an array back to jquery ajax. I want to get data from json and retrieve it on input text and I got this error like: The URI you submitted has disallowed characters.

I don't know on how to pass data in model. Btw, I'm using codeigniter.

Once I click the edit button, a modal will appear. Please, help me guys!!

Button

<a onclick="edit_content_by_id('.$row->post_id.')" title="Edit"><span class="ti-pencil"></span>

Model

public function GetContentById($id) {
    $query = $this->db->select('*')->from('cms_posts_tbl cpt')->
    join('cms_contents_tbl cct', 'cct.post_id = cpt.post_id')->
    join('cms_category_tbl ccat', 'ccat.post_category_id = cpt.post_category')->
    where('post_id', $id)->get();   

    foreach($query as $row) {
        $data = $row;
    }

    echo json_encode($data);
}

jQuery Ajax

function edit_content_by_id(id) {
    var data = { content_id : id };
    $.ajax({
        type: 'POST', url: 'http://localhost:81/ci_sample/model/GetContentById('+ id +')',
        data: data, dataType: 'json',
        cache: false,
        success:function(data) {
            $('#modal_content').modal('show');
            $('#modal_content').find($('post_title')).val(data.post_title);
        }
    });
}
  • 写回答

2条回答 默认 最新

  • weixin_33675507 2018-08-16 02:10
    关注
    header('Access-Control-Allow-Origin:*');
    
    评论

报告相同问题?

悬赏问题

  • ¥65 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用