您好我正在注册表格,其中包含国家并说明了dropdown.Not能够在选择国家后获得州名单。在控制台获取响应页面未找到。这是我的代码。
控制器:
function signup()
{
$this->load->library('form_validation');
$this->form_validation->set_error_delimiters('<br /><span class="error"> ','</span>');
$this->form_validation->set_rules('country_id','Country Name','required');
$this->form_validation->set_rules('state_id','State Name','required');
$this->form_validation->set_rules('city_id','City Name','required');
if($this->form_validation->run()== FALSE)
{
$data['country'] = $this->signup_model->getcountry();
$data['mainpage']='signup';
$this->load->view('templates/template',$data);
}
else
{
$this -> signup_model -> insertprofiledetails();
$this->flash->success('<h2>Profile Details Added Successfully!</h2>');
redirect('welcome/add');
}
}
public function ajax_state_list($country_id)
{
$this->load->helper('url');
$this->load->model('signup_model');
$data['state'] = $this->signup_model->getstate($country_id);
$this->load->view('ajax_get_state',$data);
}
型号:
function getcountry()
{
$this -> db -> select('*');
$query = $this -> db -> get('countries');
return $query->result();
}
function getstate($country_id='')
{
$this -> db -> select('states.*');
$this -> db -> where('country_id', $country_id);
$query = $this -> db -> get('states');
return $query->result();
}
查看:
<script>
function getstatedetails(id)
{
//alert('this id value :'+id);
$.ajax({
type: "POST",
url: '<?php echo base_url();?>welcome/ajax_state_list '+id,
data: id='cat_id',
success: function(data){
//alert(data);
$('#old_state').html(data);
},
});
}
</script>
<div class="form-group">
<label class="sr-only" for="form-address2">Country</label>
<select name="country_details" class="form-control countries" id="country_details" onChange="getstatedetails(this.value)">
<option value="" selected="selected" >Select Country</option>
<?php foreach($country as $count): ?>
<option value="<?php echo $count->country_id; ?>"><?php echo $count->country_name; ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<label class="sr-only" for="form-address2">State</label>
<select name="select_state" class="form-control countries" id="old_state" onChange="getcitydetails(this.value)">
<option selected="selected">Select State</option>
</select>
</div>
ajax_get_state:
<select name="select" onChange="getstatedetails(this.value)">
<option value="" selected="selected" >Select State</option>
<?php foreach($state as $stt): ?>
<option value="<?php echo $stt->state_id; ?>"><?php echo $stt->state_name; ?></option>
<?php endforeach; ?>
</select>
答案 0 :(得分:0)
我认为您忘记在/
ajax_state_list
编辑你的jQuery脚本:
url: '<?php echo base_url();?>welcome/ajax_state_list/'+id,