我的javascript代码值将打印来自ajax响应的数据
<script type="text/javascript">
function getval(get) {
var id = get.value;
// alert(id);
$.ajax({
type : "POST",
url :"http://localhost/codeIgniter/index.php/admin/ajax",
data :{id:id},
success:function(data){
$('#sub_category').html(data);
//window.location = "<?php echo site_url('admin/examdetails/form'); ?>"
}
});
}
</script>
控制器功能:将处理ajax请求
function ajax()
{
$id = $_POST['id'];
echo "<script>";
echo "alert(id);";
echo "</script>";
$this->load->model('admin_model');
$query = $this->admin_model->get_sub_details($id);
echo '<select name="sub_category" id="sub_category">';
foreach($query->result_array as $row)
{
$name = $row['name'];
$id = $row['id'];
echo '<option value="'.$id.'">'$name'</option>';
}
echo '</select>';
}