I have a big problem with a Insert Element of a multidimensional Array, that i send by AJAX.
I explain you my problem:
Here my JS Code
Code:
for(i=0; i<=length; i++){
for(j=0;j<width;j++){
// je récupère un à un (cellule par cellule) les valeurs d'un tableau html
// I get value of Cell, one and one , of my html Table
result = document.getElementById("table").rows[i].cells[j].innerHTML;
// Construct my Array
table_export[i]= new Array;
table_export[i][j] = result;
}
}
Then I send my table to php file, which return me a result of print_r($_POST)
My problem is here ! The php Fil return me this Array =>
It's hard to tell without certain parts of the code, but it looks like you might be actually sending your javascript array variable to the PHP script. If this is the case, the array variable will not properly send because you can't pass advanced data types like arrays and objects in to PHP $_POST and $_GET queries. You'll need to most likely send it as a string and then use something like explode() in PHP to break it back in to a PHP array variable.
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
// construct array multi dimensional / JS FILE
for(i=0; i<=length; i++){
// Construct my first dimensional Array
table_export[i]= new Array;
for(j=0;j<width;j++){
// I get value of Cell, one and one in my html Table
result = document.getElementById("table").rows[i].cells[j].innerHTML;
// Insert 'result' in second dimensional Array
table_export[i][j] = result;
}
}
req = { 'tab[]' : table_export};
$.ajax({
type: "POST",
url: "myphpfile.php",
data: req ,
success: function(x){
$('#result').html(x);
}
});
Bookmarks