Here I want to pass the value which am getting in data to the controller so I gave my code like this.

```
$("#sup_box").on("submit", function (e) {
    e.preventDefault();
    var toPost = $('.row_selected input').serialize();
    alert(toPost);
    $('.submit_data').text(toPost);
    $.ajax({
        type: "post",
        url: "<?php echo base_url();?>app/admin_control/add_data",
        data: toPost,
        dataType:"text",
        success: function (data) {
          alert("hai");
     },
        error: function (data) {
     alert("not");
  }
    });
});

```

My controller looks like this .

```
 public function add_data()
    {

      $bill_no = '000';
      $data = $_POST['data'];
      var_dump($data);
      $data1 = json_decode($data,true);
      var_dump($data1);
     foreach($data1 as $r) {
       $data = array('user_id'=>1,'bill_no'=>$bill_no);
       $this->Admin_model->add_data($data);

 }
}

```

But when I pass into the controller am getting error like `undefined index data` in console 

My `toPost` variable contains value like this

```
add_type%5B%5D=super&add_number%5B%5D=324&add_quantity%5B%5D=44&add_amount%5B%5D=440.00&add_checkbox=1&add_profit%5B%5D=440.00&add_agent_amount%5B%5D=0.00

```