I have a form with a submit button. When clicked, it adds listed elements to an array.

```
$("#submitButton").click(function(){
    var selection = $("#selectedList li");
    var families_selection = [];
    selection.each(function() {
        families_selection.push($(this).text().replace(/Remove/,''));
    });
 });

```

I want to use the array "families\_selection" in the controller "Provider", so I can use the following function and instert the values in a database.

```
$this->Proveedormodel->add_uk_proveedor_familia($idProveedor, $families_selection);

```

EDIT: I get the value for $idProveedor in the controller, not in the view, using another function in the same "Proveedor" model.

```
$idProveedor = $this->Proveedormodel->get_idConsecutivo();

```

This is how I insert the values in the database in my model.

```
function add_uk_proveedor_familia($id, $params){
    foreach($params as $clave){
        $this->db->select('id')->from('familia')->where('clave', $clave);
        $valor = $this->db->get();
        $vl = $valor->row_array();
        $familia = $vl['id'];
        $this->db->insert('relacionproveedorfamilia', array(
            'idProveedor' => $id,
            'idFamilia' => $familia
        ));
    }    
}

```

How can I use ajax to pass this array to the controller and use the function I need?

**Edited code using Dragan Valjak's response. Now it works!**

View add.php

```
$("#botonGuardar").click(function(){
    var seleccion = $("#listaSeleccion li");
    var familias_seleccion = [];

    seleccion.each(function() {
        familias_seleccion.push($(this).text().replace(/Quitar/,''));
    });

    $.ajax({
        url: 'Proveedor/crearRelacion',
        method: 'POST',
        data: {familias_seleccion: familias_seleccion}
    });
});

```

Controller Proveedor.php

```
function crearRelacion(){
    $this->load->model('Proveedormodel');
    $familias_seleccion = $this->input->post($data);
    $idProveedor = $this->Proveedormodel->get_idConsecutivo();
    $this->Proveedormodel->add_uk_proveedor_familia($idProveedor, $familias_seleccion);
}

```

Model Proveedormodel.php

```
function add_uk_proveedor_familia($id, $params){
    foreach($params as $clave){
        $this->db->select('id')->from('familia')->where('clave', $clave);
        $valor = $this->db->get();

        $vl = $valor->row_array();
        $familia = $vl['id'];

        $this->db->insert('relacionproveedorfamilia', array(
            'idProveedor' => $id,
            'idFamilia' => $familia
        ));
    }    
}

```