我正在尝试使用ajax在codeigniter中创建一个带子菜单的菜单我成功创建了菜单,但是当我创建一个子菜单时,我正面临问题。当我点击菜单我在cosole.log中检查它显示控制器是获取详细信息但在那之后我不知道为什么它不工作。请任何人解决这个问题。提前致谢 这是我的视图区域
<form action="" method="post" id="frm_submenu">
<div class="form-group">
<label for="menu">Select Menu</label>
<select class="form-control" id="selectmenuid">
<option value="">-- Select Menu --</option>
<?php foreach($showData as $show):?>
<option value="<?php echo $show->menu_id?>"><?php echo $show->menu_name?></option>
<?php endforeach;?>
</select>
</div>
<div class="form-group">
<label for="menu">Select Sub Menu</label>
<select class="form-control" id="selectsubmenu">
<option value="">-- Select Submenu Menu --</option>
</select>
</div>
<div class="form-group">
<label for="imagetitle">Image Title</label>
<input type="text" class="form-control" name="imagetitle" id="imagetitle" placeholder="Enter Image Title" required="required">
</div>
<div class="form-group">
<label class="btn btn-default btn-file">
Browse <input type="file" style="display: none;">
</label>
</div>
<button type="submit" class="btn btn-primary" id="submit">Submit</button>
</form>
这是我的ajax区域
$("#selectmenuid").change(function() {
var selectmenuid = $(this).val();
console.log(selectmenuid);
$.ajax({
type: "POST",
data: selectmenuid,
url: "<?= base_url() ?>Admin_Creator/SelectSubmenudropdown",
success: function(data) {
$.each(data, function(i, data) {
$('#selectsubmenu').append("<option value='" + data.submenu_id + "'>" + data.submenu_name + "</option>");
});
}
});
});
这是我的控制器区域
public function SelectSubmenudropdown()
{
if(isset($_POST['selectmenuid']))
{
$this->output->set_content_type("application/json")->set_output(json_encode($this->Model_Creator->getSubmenu($_POST['selectmenuid'])));
}
}
这是我的模范区域
public function getSubmenu(){
$this->db->select('submenu_id,submenu_name');
$this->db->from('menu,submenu');
$this->db->where('submenu.menu_id=menu.menu_id');
$this->db->where('submenu.menu_id', $selectmenuid);
return $query->result_array();
}
答案 0 :(得分:0)
您必须在模型方法中收到$selectmenuid
:
public function getSubmenu($selectmenuid){
$this->db->select('submenu_id,submenu_name');
$this->db->from('menu,submenu');
$this->db->where('submenu.menu_id=menu.menu_id');
$this->db->where('submenu.menu_id', $selectmenuid);
return $query->result_array();
}