1 回答

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
嘗試這個(gè) :
<input name="vh_stock" type="text" class="vh_stock">
至 :
<input name="vh_stock" type="text" class="vh_stock" value="">
嘗試:
控制器 => Mechanical_rdirecived/viewtankstock
public function viewtankstock()
{
$id = $this->input->post('reg_no');
$this->load->model('Model_fuel_rdirecived');
$arr = $this->Model_fuel_rdirecived->viewtankstock($id);
echo json_encode($arr);
}
模型=>Model_fuel_rdirecived->viewtankstock($id);
public function viewtankstock($id) {
$this->db->where('vh_id', $id);
$query = $this->db->get('vh_stock');
if ($query->num_rows() > 0)
{
$data['foreach'] = $query->result();
$id1 = $data['foreach'][0]->vh_id;
$vh_stock = $data['foreach'][0]->vh_stock;
$arr =array("vh_stock"=>"$vh_stock","id1"=>"$id1");
return $arr;
}
}
JavaScript 錯(cuò)誤
<script>
$(document).ready(function(){
$('#tanktype').change(function(){
var id = $(this).val();
$.post('<?php echo base_url()."index.php/Mechanical_rdirecived/viewtankstock"; ?>', { dropdownValue: id },
function(data){
alert('ajax completed. Response: '+data);//msg=ajax completed. Response: {"vh_stock":"600","id1":"4"}
$(".vh_stock").val(data.vh_stock);//no recived how can no recived data
$(".id1").val(data.id1); //no recived how can no recived data
},)
});
});
</script>
結(jié)果
ajax completed. Response: undefined
- 1 回答
- 0 關(guān)注
- 120 瀏覽
添加回答
舉報(bào)