如何将产品的ID传递给参数ajax,以在select2服务器端代码点火器上进行查询

问题描述 投票:0回答:1

我想问。我也有问题,无法从详细产品中获取ID并将其传递给控制器​​,而我的第一次尝试显示了[object Object] $ abc123。如何使从对象对象到字符串[对象对象] $ abc123变为仅$ abc123?我也想让我的select2仅显示仅适用于产品abc123的uom。

这是我的源代码JS。

$("#selUom").select2({
        ajax: {
            url: '<?=base_url("transaksi/get/uom")?>',
            type: "post",
            dataType: 'json',
            data: function(params) {
                return {
                    idprod: params+'<?php echo $detprod["productcode"]; ?>',
                    searchTerm: params.term // search term
                };
            },
            processResults: function(response) {
                return {
                    results: response
                };
            },
            cache: true
        }
    });

控制器

public function allUom(){
    $searchTerm = $this->input->post('searchTerm');
    $idprod     = $this->input->post('idprod');
    $response   = $this->M_Mstuom->allBasedUom($idprod,$searchTerm);

    echo json_encode($response);
}

型号

public function allBasedUom($id, $searchTerm=""){
    $this->db->select('m.uomid, m.uom');
    $this->db->join("msuom m", "m.uomid = pu.uomid");
    $this->db->where("m.uom like '%" . $searchTerm . "%' ");
    $this->db->where("pu.productcode", $id);
    $this->db->where("m.isactive", "t");
    $fetched_records = $this->db->get('msproductuom pu');
    $uom = $fetched_records->result_array();
    $data = array();
    foreach ($uom as $uom) {
        $data[] = array("id" => $uom['uomid'], "text" => $uom['uom']);
    }
    return $data;
}
jquery codeigniter jquery-select2
1个回答
0
投票
Try to use :
$("#selUom").select2({
        ajax: {
            url: '<?=base_url("transaksi/get/uom")?>',
            type: "post",
            dataType: 'json',
            data: function(params) {
                return {
                    idprod: params.'<?php echo $detprod["productcode"]; ?>',
                    searchTerm: params.term // search term
                };
            },
            processResults: function(response) {
                return {
                    results: response
                };
            },
            cache: true
        }
    });
© www.soinside.com 2019 - 2024. All rights reserved.