0

Jquery -> 查看 -> v_addEmployee::

function get_subdepartment() {
var dep_selected = $('select[name=txtDept]').val();
$.ajax({
    data: {
        dept: dep_selected,
    },
    type: 'POST',
    url: 'addEmployee/getSubDept',
    success: function(data){ 
        console.log(data);
        alert(dep_selected);
        $('.subDept').html(data);
    }
})

}

查看-> v_addEmployee:

                    $rs_dept = $this->m_addVacancy->getDepartment();
                $deptOption['-'] = 'Select Department';
                if ($rs_dept){
                    foreach($rs_dept as $row_dept){
                        $deptOption[$row_dept->dept] = $row_dept->dept;
                    }
                }
            //echo form_dropdown($name = 'txtDept',$Options = $department, array($this->input->post('txtDept')) ,'class="txt2" style="width: 96% " onChange="get_subdepartment1();"');
            echo form_dropdown('txtDept',$deptOption, array($this->input->post('txtDept')),'class="txt2" style="width: 96% " onChange="get_subdepartment();" onSelect="get_subdepartment();"');

控制器:在 addEmployee/getSubDept 中是否存在 addEmployee/index

        function index(){
        $this->load->helper('form');
        $this->load->view('v_addEmployee');
    }


function getSubDept(){ echo $this->input->post(dept); }

在 .subDept 中,它显示 addEmployee/index 页面。请帮忙

4

1 回答 1

0

这可能是路由问题,请尝试更改:

url: 'addEmployee/getSubDept',

url: '/addEmployee/getSubDept',

或者

url: '<?php echo base_url(); ?>addEmployee/getSubDept',

检查控制台以查看您的 ajax 帖子是否被重定向。

于 2013-02-06T09:04:51.007 回答