使用Ajax或jQuery将下拉列表中选定的值从一个视图页面发送到Codeigniter中的另一视图页面

时间:2019-03-16 05:44:41

标签: php jquery ajax codeigniter

这是我的控制器,即home.php,

function search($collg_id = '', $id = '') {
    $courserecord = $this->front->get_data_wheree('tbl_course_offered');
    $data['course_offrd_name'] = json_decode(json_encode($courserecord), True);
    if (empty($data['course_offrd_name'])) {
        $data['course_offrd_name'] = json_decode(json_encode($courserecord), True);
    } else {
        $courserecord = $this->front->get_data_wheree('tbl_course_offered');
        $data['course_offrd_name'] = json_decode(json_encode($courserecord), True);
    }
}

这是我的model.php,

function get_data_wheree($table) {
    $this->db->select('course_offrd_name, collg_id');
    $this->db->group_by('course_offrd_name');
    return $this->db->get('tbl_course_offered')->result();
}

这是我的源代码查看页面,即index.php下拉页面

<div class = "col-md-2">
    <div class = "form-group">
        <div class = "col-md-12">
            <select class = "course" name = "course_offrd-name[]" id = "course_offrd_name" class = "form-control">
                <option value = "">Select</option>
                <?php
                foreach ($coursedata as $val) {
                    ?>              
                    <option value="<?php echo $val->course_offrd_name; ?>">
                        <?php echo $val->course_offrd_name; ?>
                    </option> 
                    <?php
                }
                ?>
            </select>
        </div>
    </div>
</div> 
<script>
    $(document).ready(function () {
        $("select.course").change(function () {
            var selectedCourse = $(this).children("option:selected").val();
            alert("You have selected the course - " + selectedCourse);
        });
    });
</script>
<!--this is my  second view page ie search.php where myselected option should display--> 
<form class="form-horizontal well" action="<?php echo base_url(); ?>search" method="post" role="form">
    <span>
        <?php foreach ($coursedata as $val) {
            ?>
            <p>
                <input class="with-gap filter_course CheckCourse" name="course_offrd_name[]" multiple type="checkbox" id="<?php echo $val->course_offrd_name; ?>"  value="<?php echo $val->course_offrd_name ?>" 
                       <?php
                       if (!empty($courserecord))
                           if (count($courserecord) == 1)
                               if ($courserecord[0]['course_offrd_name'] == $val->course_offrd_name) {
                                   echo $courserecord[0]['course_offrd_name'];
                                   echo "checked";
                               } else {

                               }
                       ?> />
                <label for="<?php echo $val->course_offrd_name ?>"></label>
            </p>
        <?php } ?> 
    </span>
    <br>
</form>

我想使用Ajax或jQuery将选择的值从一个视图页面发送到codeigniter中的另一个视图页面。 所选择的选项值应从index.php发送到search.php。它应该只在search.php中显示值名称 如果需要,将提供更多代码。 怎么办?
现在,我在search()函数中有代码。 我对代码进行了更改。 请参阅此搜索功能。 预先感谢!

0 个答案:

没有答案