依赖下拉列表无法使用codeigniter

时间:2013-12-22 06:42:51

标签: php jquery codeigniter

在下面的codeigniter代码中,我已经放置了控制器,模型和视图。我的目标是当我选择考试名称时,它应该从考试表中删除相应的课程代码。但是当我选择考试名称时,我的实际结果并没有丢弃下拉列表。请帮我这样做。

控制器:进口

public function index()

    {   
//echo "inside form upload";   

        $data = array();
        //$college_name = $this->session->userdata('college_name');
        if($query = $this->import_model->get_exam_data())
        {
            $data['exam_data'] = $query;
        }
        //$this->load->view('student_view', $data);

        $this->load->view('form_upload',$data);
    }
    function subjectcodedetails()
    {   
        $data = array();
        //$college_name = $this->session->userdata('college_name');
        $exam_name = $this->input->post('exam_name');
        //$course_name = $this->input->post('course_name');
        if($query = $this->import_model->get_subject_records($exam_name))
        {
            $data['course_code'] = $query;
        }
        $this->load->view('subject_view', $data);
    }

<小时/> 的模型:

function get_exam_data()
    {
        $this->db->distinct();
        $this->db->select("CONCAT(exam_name) AS fullexamname", FALSE);//this will concat the value
        //$this->db->where('college_name',$college_name);
        $query = $this->db->get('examcourse');
        return $query->result();
    }
    function get_subject_records($exam_name)
    {
        //echo "exam_name inside get_subject_records".$exam_name;
        $this->db->select('course_code');
        //$this->db->where('exam_name',$exam_name);
        $this->db->where('fullexamname',$exam_name);
        //$this->db->where('college_name',$college_name);
        $query = $this->db->get('examcourse');
        return $query->result();

    }

<小时/> 查看: form_upload

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
   <script type="text/javascript">
    $(document).ready(function(){
        $(".dropdown_class").change(function()
        {
            var id=$(this).val();
            // Please find the course_code, course_code was not found
            var dataString = 'course_code='+ id;
            $.ajax
            ({
                type: "POST",
                url: "import/subjectcodedetails",
                data: dataString,
                cache: false,
                success: function(html)
                {
                    $(".dropdown_class12").html(html);
                } 
            });

        });
</script>
<form action="http://localhost/CodeIgniter/index.php/import/upload" method="post" accept-charset="utf-8" enctype="multipart/form-data">        <?php 
        $data = array();
        $data["Select Exam Name"] = "Select Exam Name"; 
        foreach ($exam_data as $row)
        {
            $data[$row->fullexamname] = $row->fullexamname; 
        }
        echo form_dropdown('exam_name', $data, 'small', 'class="dropdown_class"  id="exam_name_id" ');
?>

<小时/> 查看:subject_view

<?php 
        $data = array();
        foreach ($course_records as $row)
        {
            $data[$row->course_code] = $row->course_code; 
        } 
        echo form_dropdown('course_name', $data, 'small','class="dropdown_class12"  id="course_name_id"');
?>  

1 个答案:

答案 0 :(得分:0)

$(document).ready(function () {
    $(".dropdown_class").change(function () {
        var id = $(this).val();
        // Please find the course_code, course_code was not found
        var dataString = 'course_code=' + id;
        $.ajax({
            type: "POST",
            url: "import/subjectcodedetails",
            data: dataString,
            cache: false,
            success: function (html) {
                $(".dropdown_class12").html(html);
            }
       });

    });
};

}阻止

结束时遗失$(document).ready