0
我有一個登記表,其中包括州和市下拉菜單。然而,在選擇一個州之後,它無法獲得城市的名單。下拉式阿賈克斯州和市不起作用
在控制檯下面似乎對我來說,答案是:
無法加載資源:服務器與404狀態響應(未找到)。
布拉斯德區Y comuna
|----------------------------|
| tbl_state |
|----------------------------|
| id_state |
| name_state |
|----------------------------|
|----------------------------|
| tbl_city |
|----------------------------|
| id_city |
| name_city |
| state_id |
|----------------------------|
這裏是我的代碼。
控制器:
public function index()
{
//State
$data['result_state'] = $this->state_model->getState();
$this->load->view('interprete_registro_view',$data);
}
public function city()
{
$id = $this->input->get('id_state');
$this->state_model->getCity($id);
}
型號:
public function getState()
{
$this->db->select('*');
$this->db->from('tbl_state');
$query = $this->db->get();
$query_result = $query->result();
return $query_result;
}
public function getCity($id)
{
$query = $this->db->where('state_id', $id)->get('tbl_city');
$cad = "";
foreach ($query->result_array() as $row) {
$cad .= "<option value='{$row['id_city']}'>{$row['name_city']}</option>";
}
echo $cad;
}
檢視:
<script type="text/javascript">
var path = '<?php echo base_url()?>index.php/';
$(document).ready(function() {
carga();
$('#state').change(carga);
});
function carga() {
var cd = $('#state').val();
$.get(path + 'registre/city', {'id' : cd}, function(resp) {
$('#city').empty().html(resp);
});
}
</script>
<div class="col-2">
<label for="state">State <span> * </span></label>
</div>
<div class="col-3">
<select class="form-control" name="state" id="state">
<option value="" selected>- state -</option>
<?php foreach($result_state as $row):?>
<option value="<?php echo $row->id_state;?>"><?php echo $row->name_state;?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-2">
<label for="city">City <span> * </span></label>
</div>
<div class="col-3">
<select class="form-control" name="city" id="city">
<option>- city -</option>"
</select>
</div>
任何想法,溶液或尺寸是受歡迎的。
請問'http:// www.yourUrl.com/index.php/registre/city'本身在瀏覽器中工作還是返回404?如果它起作用,你的腳本集中的'path'是否正確? – ourmandave
在'config.php'什麼是分配給'$ config ['base_url']'?您是否使用'.htaccess'來重寫您的網址? – DFriend