如何在ajax提供的控制器中检索文本框值


How to retrieve textbox value in a controller which is supplied with ajax?

我想把文本框的值传递给我的控制器,我可以传递,但我不能在控制器上检索。帮我认错。

Form.php(dept_name是我的文本框的id)

<script>   
                    $(document).ready(function() {
                        $("#submitbutton").click(function(e) { 
                            var deptname=$('#dept_name').val();                           
                            $.ajax({
                                url: 'http://localhost/finalProjectWork/admin_department_controller/adddept/',
                                type: 'POST',
                                method: 'POST',
                                headers: {'Cache-Control': 'no-cache'},
                                data: {name:deptname},
                                contentType: false,
                                processData: false,
                                success: function(test) {
                                    alert(test);
                                },
                                error: function() {
                                    alert("Already Exists");
                                }
                            });
                            e.preventDefault(); 
                        });
                    });</script>

控制器:

 public function adddept()
    {
        $deptname=$this->input->post('name');
        $this->load->model('admin_department_model');
        $this->admin_department_model->insertdept($deptname);
        echo "Successfully inserted";
    }

试试这个

<script>   
                    $(document).ready(function() {
                        $("#submitbutton").click(function(e) { 
                            var deptname=$('#dept_name').val();                           
                            $.ajax({
                                url: 'http://localhost/finalProjectWork/admin_department_controller/adddept/',
                                type: 'POST',
                                method: 'POST',
                                headers: {'Cache-Control': 'no-cache'},
                                data: {name:deptname},
                                success: function(test) {
                                    alert(test);
                                },
                                error: function() {
                                    alert("Already Exists");
                                }
                            });
                            e.preventDefault(); 
                        });
                    });</script>