像这样看:
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label for="inputEmail3" class="col-sm-4 control-label">Brand Name</label>
<div class="col-sm-8">
<select class="form-control" id="brand_mod" name="brand_name" required>
<option value="" selected disabled="disabled">Select Brand Here</option>
<?php foreach($b->result() as $row) { ?>
<option value="<?php echo $row->id; ?>"> <?php echo $row->brand_name; ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label for="inputPassword3" class="col-sm-4 control-label">Model</label>
<div class="col-sm-8">
<select name="model_number" class="form-control" id="models">
<option value="">--Select model --</option>
</select>
</div>
</div>
</div>
</div>
在品牌名称下拉品牌名称下面是正确可见的,有我的型号名称下拉列表...我想当我点击任何品牌名称时,其模型会在模型下拉列表中显示 然后我的ajax电话是
<script>
$('#brand_mod').change(function(){
var bbb = $('#brand_mod').val();
//alert(bbb);
$.ajax({
type: "GET",
url: '@Url.Action("<?php echo base_url(); ?>User/get_models", "Application")',
contentType: "application/json; charset=utf-8",
data: { brand_id : $('#brand_mod').val() },
dataType: "json",
cache: false,
success: function(data)
{
alert(data);
alert('Success');
return false;
},
error:function()
{
alert('error');
return false;
}
});
});
</script>
然后我的控制器就像这样进行ajax调用
public function get_models(){
$id = $this->input->post('brand_id');
$this->load->model("user/User_model");
$result1 = $this->User_model->all_models($id);
//$data = array();
'<option value=""></option>'
foreach($result1 as $row)
{
'<option value="'.$row->id'">'.$row->model_name'</option>'
}
}
我的模特是
public function all_models($id)
{
$this->db->where('brand_id',$id);
$query = $this->db->get('wc_models');
return $query->result_array();
}
但是我收到错误警告......代码有问题......我已经尽力了......请帮忙......