I have tried a lot and search a lot and i did the same as i see but i do not know where i am going wrong i am new to codeigniter. Can you please tell me where i am going wrong on the code ? I want to set the product name in my input field according to the barcode selected. I am trying to fetch the product name and try to set it using AJAX but it is not working. Please you tell where is the bug in my code?

Here is my Controller Function in Main.php

```
 public function get_product()
    {   

        if (!$this->input->is_ajax_request()) {
           exit('No direct script access allowed');
        }
        $barcode = $_POST['barcode'];
        echo $barcode;
        exit;
        $data['result'] = $this->Item_model->get_product_using_barcode($barcode);
        print_r($data);
        exit;

    }

```

My Ajax Code in js file :

```
$("#brcode").each(function(){

           $("#brcode").change(function(){

                    let value = $("#brcode").val();

                    $.ajax({
                            url: '<?php echo site_url("main/get_product"); ?>',
                            type: 'POST',
                            data: {'barcode': $('#brcode option:selected').val() },
                            dataType: 'json',
                            success: function(data) {
                            //console.log(data);
                            alert(data);
                        }
                    })
           });

        });

```

Model Function :- 

```
public function get_product_using_barcode($barcode){
         $query = $this->db->get_where('items',array('barcode' => $barcode));
         $result = $query->row();
         return $result;

     }

```

Please tell me where i am going wrong in my code?