Codeigniter Ajax使用Ajax代码将数据发送到控制器 [英] Codeigniter ajax send data to controller using ajax code

查看:101
本文介绍了Codeigniter Ajax使用Ajax代码将数据发送到控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<script type="text/javascript">
    $(document).ready(function () {
        $("#select-dept").change(function () {
            var id = $("#select-dept").val();
            $.ajax({
                type: "POST",
                url: "<?=base_url()?>.index.php/sms/get_dept_employee",
                //url: baseurl + 'sms/get_dept_employee',
                data: "id",
                dataType = "json",
                cache: "false",
                success: function (emp_list) {
                    $("#dept-emp").html(emp_list);
                }
            });
        });
    });
</script>

我无法将视图数据发送到控制器功能 在视图中,它们是带有来自mysql数据库的departmenr值的选择框

I am unable to send view data to controller function In view their is select box with departmenr values from mysql database

<select class="select-dept" id="select-dept" name="select-dept">
    <option>Select Department</option>
    <?foreach ($departments as $dt):?>
        <option value="<?=$dt['id']?>">
            <?=$dt[ 'name']?>
        </option>
    <?endforeach;?>
</select>

当用户选择部门并且需要调用控制器功能时,我需要刷新 get_dept_employee 并且需要显示员工列表的数据网格

i need to get refresh when user select department and that need to call controller function get_dept_employee And need to display datagrid of employee list

推荐答案

您需要将数据选项作为对象发送

you need to send data option as object

尝试

 .....
 url: "<?=base_url()?>.index.php/sms/get_dept_employee",
 data: {"id":id},
 dataType:"json",
 ....

,并在控制器中以id形式获得过帐值.

and get the posted value as id in your controller..

$id=$this->input->post('id');
....

这篇关于Codeigniter Ajax使用Ajax代码将数据发送到控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆