JSON响应在下拉列表中填充undefine

时间:2017-11-01 10:16:17

标签: php jquery json

JSON响应没有填充在dropdown perhap查询gat中,结果完美无缺。 警告成功功能,即  alert(result.data); - [object object]

这是我的HTML代码

Jquery的

function fillTransferJobPositionAreaDropDown( job_type_id,province_id,region_id,district_id,tehsil_id,uc_id, area_id) {
    var loadDDUrl = baseApiUrl + "Employee/all_new_job_positions_area/"+job_type_id+"/"+province_id+"/"+region_id+"/"+district_id+"/"+tehsil_id+"/"+uc_id+"/"+area_id;
    console.log(loadDDUrl);
    debugger;
    newJobPositionIDFld.empty();
    newJobPositionIDFld.append($("<option     />").val("0").text("Select New Job Position"));
    newJobPositionIDFld.select2('val', '0');

    var url = loadDDUrl;
    $.ajax({
        url: url,
        accepts: 'application/json',
        cache: false,
        type : 'GET',
        dataType: 'jsonp',
        success: function (result) {
            alert(result.data);
            console.log(result.data);
            // Handle the complete event
            if(result.data == null) return;

            $.each(result.data, function () {
                newJobPositionIDFld.append($("<option     />").val(this.job_position_id).text(this.job_position_id+'-'+this.job_name));
            });
        }
    });
}//End Ajax call

PHP

$this->db->select('jp.job_position_id,jp.jobposition_title as job_name');
        $this->db->from('job_positions jp');


    $this->db->where('jp.job_type_id', $job_type_id);
    $this->db->where('jp.province_id', $province_id);
    $this->db->where('jp.region_id', $region_id);
    $this->db->where('jp.district_id', $district_id);
    $this->db->where('jp.tehsil_id', $tehsil_id);
    $this->db->where('jp.uc_id', $uc_id);
    $this->db->where('jp.area_id', $area_id);

   $this->db->get()->row_array();

1 个答案:

答案 0 :(得分:0)

您的查询返回一个对象,而不是一个对象数组,因此请删除循环:

success: function (result) {
     newJobPositionIDFld.append($("<option/>").val(result.data.job_position_id).text(result.data.job_position_id+'-'+result.data.job_name));
}