我试图使用 select2 ajax selectbox(selectbox2.github.io)将所有值保存为数组但是我的控制器类没有从codeigniter中的视图类中获取任何值,我用普通文本框替换了select2框,然后它正常工作。
问题:
1.为什么select2没有将值传递给我的控制器类,或者我的控制器类没有从视图类中获取值。
2.我创建了追加类函数来添加新的空白行select2元素,当我的页面加载追加函数正常工作但当我试图在点击事件上调用相同的函数时,屏幕上没有任何内容。
<hr />
<?php
echo form_open(base_url().'index.php?admin/classroutine_bulk_add/create',
array('class' => 'form-inline validate', 'style' => 'text-align:center'));
?>
<div class="row">
<div class="col-md-1"></div>
<div class="col-md-3">
<div class="form_group">
<label class="control-label" style="margin-bottom: 5px;">
<?php echo get_phrase('class'); ?>
</label>
<select name="class_id" id="class_id" class="form-control selectboxit" required="required"
onchange="get_sections(this.value)" data-validate="required" data-message-required="
<?php echo get_phrase('value_required'); ?>">
<option value="">
<?php echo get_phrase('select_branch'); ?>
</option>
<?php
$classes = $this->db->get('class')->result_array();
foreach($classes as $row):
?>
<option value="
<?php echo $row['class_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
</div>
<div id="section_holder"></div>
<div class="col-md-3"></div>
</div>
<br>
<br>
<div id="bulk_add_form">
<div id="classroutine_entry">
<div class="row" style="margin-bottom:10px;">
<div class="form-group">
<select name="day[]" id="day" class="form-control select2" style="width: 130px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('day'); ?>
</option>
<option value="mon">
<?php echo get_phrase('monday'); ?>
</option>
<option value="tue">
<?php echo get_phrase('tuesday'); ?>
</option>
<option value="wed">
<?php echo get_phrase('wednesday'); ?>
</option>
<option value="thurs">
<?php echo get_phrase('thursday'); ?>
</option>
<option value="fri">
<?php echo get_phrase('friday'); ?>
</option>
</select>
</div>
<div class="form-group">
<select name="period_id[]" id="period_id" class="form-control select2" data-validate="required"
data-message-required="
<?php echo get_phrase('value_required'); ?>" style="width: 130px; margin-left: 15px;">
<option value="">
<?php echo get_phrase('period'); ?>
</option>
<?php
$periods = $this->db->get('period')->result_array();
foreach($periods as $row):
?>
<option value="
<?php echo $row['period_id']; ?>">
<?php echo $row['name']; ?>
<?php echo $row['time']; ?>
</option>
<?php
endforeach;
?>
</select>
</div>
<div class="form-group">
<select name="subject_id[]" id="subject_id" class="form-control select2" style="width: 140px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('subject'); ?>
</option>
<?php
$subjects = $this->db->get('subject')->result_array();
foreach($subjects as $row):
?>
<option value="
<?php echo $row['subject_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<select name="room_id[]" id="room_id" class="form-control select2" style="width: 150px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('room'); ?>
</option>
<?php
$rooms = $this->db->get('room')->result_array();
foreach($rooms as $row):
?>
<option value="
<?php echo $row['room_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<select name="teacher_id[]" id="teacher_id" class="form-control select2" style="width: 300px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('teacher'); ?>
</option>
<?php
$rooms = $this->db->get('teacher')->result_array();
foreach($rooms as $row):
?>
<option value="
<?php echo $row['teacher_id']; ?>">
<?php echo $row['name']; ?>
<?php echo $row['email']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<select name="tutorial_id[]" id="tutorial_id" class="form-control select2" style="width: 100px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('tutorial'); ?>
</option>
<?php
$rooms = $this->db->get('tutorialgroup')->result_array();
foreach($rooms as $row):
?>
<option value="<?php echo $row['tutorialgroup_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<select name="mentorgroup_id[]" id="mentorgroup_id" class="form-control select2" style="width: 100px; margin-left: 5px;">
<option value="">
<?php echo get_phrase('lab'); ?>
</option>
<?php
$rooms = $this->db->get('mentorgroup')->result_array();
foreach($rooms as $row):
?>
<option value="<?php echo $row['mentorgroup_id']; ?>">
<?php echo $row['name']; ?>
</option>
<?php endforeach; ?>
</select>
</div>
<div class="form-group">
<button type="button" class="btn btn-default " title="
<?php echo get_phrase('remove'); ?>"
onclick="deleteParentElement(this)" style="margin-left: 10px;">
<i class="entypo-trash" style="color: #696969;"></i>
</button>
</div>
</div>
</div>
<div id="classroutine_entry_append"></div>
<br>
<div class="row">
<center>
<button type="button" class="btn btn-default" onclick="append_classroutine_entry()">
<i class="entypo-plus"></i>
<?php echo get_phrase('add_a_row'); ?>
</button>
</center>
</div>
<br>
<br>
<div class="row">
<center>
<button type="submit" class="btn btn-success" id="submit_button">
<i class="entypo-check"></i>
<?php echo get_phrase('save_class_routine'); ?>
</button>
</center>
</div>
</div>
<?php echo form_close(); ?>
<script type="text/javascript">
var blank_classroutine_entry = '';
$(document).ready(function () {
blank_classroutine_entry = $('#classroutine_entry').html();
for ($i = 0; $i
< 18; $i++) {
$("#classroutine_entry").append(blank_classroutine_entry);
}
});
function get_sections(class_id) {
$.ajax(
{
url: '<?php echo base_url(); ?>index.php?admin / get_bulkclassroutine_sections / ' + class_id,
success: function (response)
{
jQuery('#section_holder').html(response);
jQuery('#bulk_add_form').show();
}
});
}
function append_classroutine_entry()
{
$("#classroutine_entry_append").append(blank_classroutine_entry);
}
// REMOVING
function deleteParentElement(n)
{
n.parentNode.parentNode.parentNode.removeChild(n.parentNode.parentNode);
}
</script>
function classroutine_bulk_add($param1 = '')
{
if($this->session->userdata('admin_login') != 1)
redirect(base_url(), 'refresh');
if($param1 == 'create')
{
$days = $this->input->post('day');
$period_ids = $this->input->post('period_id');
$subject_ids = $this->input->post('subject_id');
$room_ids = $this->input->post('room_id');
$teacher_ids = $this->input->post('teacher_id');
$mentorgroup_ids = $this->input->post('mentorgroup_id');
$tutorialgroup_ids = $this->input->post('tutorialgroup_id');
$classroutine_entries = sizeof($room_ids);
for($i = 0; $i < $classroutine_entries; $i++)
{
$data['day'] = $days[$i];
$data['period_id'] = $period_ids[$i];
$data['subject_id'] = $subject_ids[$i];
$data['room_id'] = $room_ids[$i];
$data['teacher_id'] = $teacher_ids[$i];
$data['mentorgroup_id'] = $mentorgroup_ids[$i];
$data['tutorialgroup_id'] = $tutorialgroup_ids[$i];
$data['class_id'] = $this->input->post('class_id');
$data['section_id'] = $this->input->post('section_id');
$data['semester_id'] = $this->input->post('semester_id');
$data['year'] = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
// validate here, if the row(name, email, password) is empty or not
if($data['day'] == '' || $data['period_id'] == '' || $data['subject_id'] == '' || $data['teacher_id'] == '' || $data['mentorgroup_id'] == '' ||
$data['tutorialgroup_id'] == '')
redirect(base_url().'index.php?admin/', 'refresh');
$this->db->insert('class_routine', $data);
}
$this->session->set_flashdata('flash_message', get_phrase('class_routines_added'));
redirect(base_url().'index.php?admin/classroutine_bulk_add/', 'refresh');
// redirect(base_url() . 'index.php?admin/class_routine_view/' . $this->input->post('class_id') , 'refresh');
}
$page_data['page_name'] = 'classroutine_bulk_add';
$page_data['page_title'] = get_phrase('add_bulk_classroutine');
$this->load->view('backend/index', $page_data);
}
答案 0 :(得分:0)
我使用Jason这样的东西:
我的JS:
function deletefile(delstring_val,typestring_val,filedirectory_val)
{
if(r == true)
{
$.ajax({
url: 'delete.php',
data: {delstring: delstring_val, typestring: typestring_val},
type: 'POST',
success: function (response) {
alert(response);
document.location.href = newURL;
},
error: function () {
alert('ERROR deleting the item !!');
}
});
}
else
{
alert('Item deleting was cancel !!');
}
}
我的HTML:
<td> <a href='#' onclick = 'deletefile("<?php echo $basedir."/".$dir."/".$files[$row1];?>","<?php echo $tipo[$row1];?>","<?php echo $dir;?>");'>Delete</a> </td>
在我的Delete.php中:
$testetype=$_POST['typestring'];
如果你需要帮助,它会起作用,评论我会尽力帮助你。