douxun4173 2019-03-22 06:20 采纳率: 0%
浏览 55

无法将下拉选择选项从index.php发送到控制器,然后再发送到codeigniter中的search.php

This is my index.php

<form class="form-horizontal well bar" action="<?php echo base_url();?>search" method="post" role="form">
    <div class="col-md-2">       
        <div class="form-group">
            <div class="col-md-12">
                <select class = "course" name = "course_offrd-name[]" onchange="" 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> 
</form>

This is Javascript code in index.php page

<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 ajax code in index.php page

<script type="text/javascript">
jQuery(document).ready(function($) {
    $(".course").on('change', function() 
    {
        var level = $(this).val();
        if(level)
        {
            $.ajax ({
                type: 'POST',
                url: base_url+"home/search",
                data: {course_offrd_name: selectedCourse},
                success : function(htmlresponse) 
                {
                    $('#opt_lesson_list').html(htmlresponse);
                    console.log(htmlresponse);
                }
            });
        }
    });
});
</script>

This is my controller

public function search()
{
    $id = $this->input->post('course_offrd_name');

    $data['result']   = $this->front->get_data_wheree($id);
    $this->load->view('home/search', $data);
}

This is my model

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();
}

This is search.php file ie here i want to display the selected dropdown option

<?php 
foreach($result as $row)
{
    echo $row['course_offrd_name'];
}
?>

Satabase table name is tbl_course_offered it has collg_id and course_offrd_name column.

My dropdowndown option is comming from course_offrd_name

Problems: I have page index.php and I have two dropdown option say two courses science and Maths.
If i selected science from downdown and submit the button it redirect the page to search.php and should display science on search.php page.

I have used ajax code for that trying to send the data to controller and then to search.php but not getting the result.

My dropdown option is actually not able to send inside the controller search function and then to search.php.

What is the issue in the code?

my dropdown option send is failed from ajax to controller only and then to controller to search.php.

I m using Codeigniter3
why i m not able to send the dropdown option from index.php to controller and then to search.php page?
why i m not getting the post data in controller?

If any file is required will help you.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向