Codeigniter ajax send data to controller using ajax code

ajax, codeigniter, jquery, php

Solution

you need to send data option as object

try this

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

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

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

Problem

``` <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> ``` 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> ``` 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

Original source