所选值应显示警报消息

时间:2013-12-21 17:56:08

标签: php ajax codeigniter jquery

在下面的 codeigniter 代码中,我放置了控制器,型号视图部分。我的目标是,如果我从下拉列表中选择考试名称,它应该提醒所选的exam。我的实际结果是,如果我选择考试名称,它会抛出“hai”警告信息而不是考试名称。请解决我的问题。

控制器:

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

<小时/> 查看:

<script type="text/javascript" charset="utf-8">
 function get_subjectcodedetails() {
alert("hai");
        //var course_name = jQuery('#course_name_id').val();
        var exam_name = jQuery('#exam_name_id').val();

        //alert("course_name"+course_name);
        alert("exam_name"+exam_name);
        jQuery.ajax({
        data: '&exam_name='+exam_name,
        type: 'POST',
        url: 'import/subjectcodedetails',
        success: function(data){
            //alert("inside change"+data);
            console.log(data);
            jQuery('#ssubject_code').html(data);
        }
    });

} 
</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" onChange="get_subjectcodedetails()"');
?>
<div id="ssubject_code">

2 个答案:

答案 0 :(得分:0)

我可以建议删除

 alert("hai");

答案 1 :(得分:0)

试试这个

<script type="text/javascript" charset="utf-8">
 function get_subjectcodedetails(obj) {        
    var exam_name = obj.value; // getting value        
    alert("exam_name"+exam_name);
    jQuery.ajax({
    data: 'exam_name='+exam_name,
    type: 'POST',
    url: 'import/subjectcodedetails',
    success: function(data){
        //alert("inside change"+data);
        console.log(data);
        jQuery('#ssubject_code').html(data);
    }
});

} 
</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" onChange="get_subjectcodedetails(this)"');
?>