I am working on a personal project and I have a question about the passage of data to php.
It turns out that in js I keep changing the colors of the div (the colors are initially loaded through a query to a bd) in an array, with the code and the color (they can be 2, these represent them with 0) or 1).
What I need is that by pressing a button, the states in the bd are updated. The problem is that I can not send the array of js to php. I tried with the following function:
$.ajax({ url: 'cursos/guardarmalla',
data: {'actualizar' : actualizar},
type: 'post',
dataType:'json',
success: function(output) {
alert(output);
}
});
but I do not know how to put the button together and send the array.
function to send the data:
function enviararray() {
$.ajax({ url: 'cursos/guardarmalla',
data: {actualizar},
type: 'post',
dataType:'json',
success: function(output) {
alert(output);
}
});
}
var actualizar=[];
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;
}
Those are the functions of js that I use to modify the update array.
This is the html of the button
<?php echo form_open("/cursos/guardarmalla");?>
<div align="center"><?php echo form_submit('','Guardar Malla',"class=\"btn btn-success btn-lg\" onclick=\"enviararray()\"");?></div>
<?php echo form_close()?>