0

Im try to send an array to my controller in Codeigniter,To then be able to use this array in my controller, but gettting a problem in the creation the array repeat the line enter image description here

here my js function

 function get_array(){
   var datos = [];
   row = {};
  $("#tbl_esctructura tbody > tr").each(function() {
    var item = $(this).find('td:eq(1)').text();
    var cantidad = $(this).find('td:eq(3)').text();
     row["item"] = item;
     row["cantidad"] = cantidad;
     datos.push(row); // you push it to the array
  });

    datos =  JSON.stringify(datos);
}

here my controller

public function data_from_array(){
    $data   =  array($this->input->post('datos', TRUE));

    foreach ($data as $row) {

        echo $row;
    }
}

1 Answer 1

1

Please modify your code like that.

 function get_array(){
   var datos = [];
  $("#tbl_esctructura tbody > tr").each(function() {
    var row = {};
    var item = $(this).find('td:eq(1)').text();
    var cantidad = $(this).find('td:eq(3)').text();
     row.item = item;
     row.cantidad = cantidad;
     datos.push(row); // you push it to the array
  });

    datos =  JSON.stringify(datos);
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.