0
將參數傳遞給控制器我試圖實現的是,當我從下拉列表中選擇一個人時,他的電話號碼應該出現在相鄰文本框中的下拉變化功能上。 我已經能夠在下拉菜單中從數據庫中獲取人名。無法從視圖
這裏的型號代碼:
public function get_phone_id($id)
{
$this->db->select('dealerphone');
$this->db->where('dealerid',$id);
$query = $this->db->get('Dealer');
$result=$query->result_array();
return $result;
}
控制器代碼:
public function dealer_phone($id)
{
$list = $this->person->get_phone_id($id);
// print_r($list);
echo json_encode($list);
}
查看代碼:
<script>
$("#select").change(function() {
var getValue = $(this).find('option:selected').attr('id');
get_phone(getValue);
});
function get_phone(id) {
alert(id);
$.ajax({
url: "<?php echo site_url('dealer_controller/dealer_phone')?>/" + id
, type: "POST"
, dataType: "JSON"
, async:false
, success: function() {
//if success reload ajax table
console.log();
}
, error: function (xhr,status) {
console.log(status);
}
});
}
</script>
我現在面臨的唯一問題是,我無法通過「 getValue'到控制器功能。
聲明AJAX POST方法你能檢查瀏覽器控制檯什麼是請求和響應值? – Tpojka
請添加您的html – Vickel