gpt4 book ai didi

php - Codeigniter ajax 国家/地区下拉列表不起作用

转载 作者:行者123 更新时间:2023-11-30 22:10:20 25 4
gpt4 key购买 nike

您好,我有注册表单,其中包含国家和下拉列表。在选择国家后无法获得州列表。在控制台中收到响应,因为找不到页面。这是我的代码。

Controller :

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>

最佳答案

我认为你忘记在 ajax_state_list 之后使用 /

编辑你的 jQuery 脚本:

url: '<?php echo base_url();?>welcome/ajax_state_list/'+id,

关于php - Codeigniter ajax 国家/地区下拉列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40281288/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com