为什么我的AJAX调用未将数据传递到给定的URL?它也没有显示任何错误。如何获得基于所选州的城市列表?
<label>State</label>
<select name="state" id="state">
<option value="" disabled selected>Choose your state</option>
<?php foreach($states as $state){
echo '<option value="'.$state['state_id'].'">'.$state['state_name'].'</option>';
} ?>
</select><br><br>
<label>Aperture Place</label>
<select name="aperture_place" class="city">
<option value="" disabled selected>Choose your city</option>
</select><br><br>
$(document).ready(function() {
jQuery('#state').change(function() {
var id = jQuery(this).val();
//alert(id);
jQuery.ajax({
type: 'post',
url: "<?php echo base_url().'routes/get_city' ?>",
data: 'id=' + id,
success: function(result) {
alert(result);
//jQuery('.city').html(result);
}
});
});
});
public function get_city()
{
$id = $_POST['id'];
$query = $this -> common -> select_data_by_id('city', 'state', $id, '*', '');
print_r($query);
exit();
echo '<option value="" disabled selected>Choose your city</option>';
foreach($query as $place) {
echo '<option value="'.$place['city_name'].'">'.$place['city_name'].'</option>';
}
}