I need to send an array of java script to php, this is the idea that I have made but it does not work, if you can help solve the problem or find another way to do it I would appreciate it.
The idea is to reload the entire page again.
I have problems sending a JSON to a controller via AJAX, the JS alert works and the JSON shows me, but the controller is not receiving the data.
creation of 'actualizar':
var actualizar = new Object();
function myButton_onclick(x,id) {
if(x.style.backgroundColor=='rgb(255, 114, 144)')
{
x.style.backgroundColor='rgb(90,237,247)';
actualizar[id]=1;
}else{
x.style.backgroundColor='rgb(255, 114, 144)';
actualizar[id]=0;
}
console.log(actualizar)
return false;
}
view:
$id= array('id' => 'x' );
echo form_open("cursos/guardarmalla",$id);?>
<div align="center"><?php echo form_submit('','Guardar Malla',"class=\"btn btn-success btn-lg\"");?></div>
<?php echo form_close()?>
<script type="text/javascript">
$(document).ready(function(){
$('#x').submit(function(){
var aux = JSON.stringify(actualizar);
$.ajax({
type :'POST',
url: $(this).attr("action"),
dataType: "json",
data : aux
});
alert(aux);
})
})
</script>
controller:
function guardarmalla(){
$datos= $this->input->post('aux');
$deco=json_decode($datos,true);
echo "Los datos recibidos son".$deco;
}
I regret having the variables in Spanish. I'm from Chile and in stackoverflow in Spanish I had no answer
EDIT
I think the problem is that ajax does not cause the driver function to run
EDIT EDIT
Investigating arrives at the conclusion that AJAX is not necessary, since I want to reload the whole page again, but I do not know how to send an Array or JSON they are the "submit" button to PHP