小编Ae9*_*e98的帖子

从.post中检索数据

我正在使用codeigniter,我有一个问题,使用jQuery $.post函数处理数据.我想给这样的值,subjectid以ajax_get_subject_credit同一个数据库表中的功能和检索另一个领域.结果显示在另一个文本字段中.这是我的代码.

视图:

$.post('<?php echo site_url('academic/ajax_get_subject_credit'); ?>', {'subjectid':subjectid}, function(data){

        $('#chours' + id).val(data); });
Run Code Online (Sandbox Code Playgroud)

这从下拉列表获取值,我想从下拉列表中自动填充文本字段.#chours是文本字段ID.

控制器:

function ajax_get_subject_credit($result)
{
    $this->db->select('subjectid, subjectcredit');
    $query = $this->db->get('ref_subject');
    $result = $query->result_array();
    $query->free_result();
    $subjectid = array();
    foreach($result as $row)
    {
        $result = $result + array($row['subjectid'] => $row['subjectcredit']);
    }
    return $result;
}
Run Code Online (Sandbox Code Playgroud)

在控制器中修改

我也尝试在控制器中使用这个语句直接调用该字段但仍然没有成功:

function ajax_get_subject_credit($subjectid)
{
    $this->db->select('subjectid, subjectcredit');
    $this->db->where('subjectid',$subjectid);
    $query = $this->db->get('ref_subject');
    $credithour = $query->row()->subjectcredit;
    $query->free_result();
    echo $credithour;
}
Run Code Online (Sandbox Code Playgroud)

javascript php jquery codeigniter .post

2
推荐指数
1
解决办法
164
查看次数

标签 统计

.post ×1

codeigniter ×1

javascript ×1

jquery ×1

php ×1