Transmettre un tableau en paramètre (Ajax/Jquery)
Bonjour tout le monde, je voudrais savoir s'il est possible de passer un tableau en paramètre de $.ajax.
J'ai essayé de le faire comme ceci, mais cela ne fonctionne pas ou il me manque peut être quelque chose dans ma fonction php.
Voici mon code js :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| function ConfirmMessage(zones) {
if (confirm("Etes-vous sûr de vouloir sauvegarder les modifications ?")) {
var tab = new Array();
for(var i=0;i<zones.length;i++) {
var name = zones[i];
var nom = "zone"+name;
var top = document.getElementById(nom).style.top;
var left = document.getElementById(nom).style.left;
var width = document.getElementById(nom).style.width;
var height = document.getElementById(nom).style.height;
tab[i] = new Array();
tab[i]['nom'] = nom;
tab[i]['top'] = top;
tab[i]['left'] = left;
tab[i]['width'] = width;
tab[i]['height'] = height;
jQuery.ajax({
type: "POST",
url: "update_product_sheet",
data: { tab: tab }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
} |
et mon code php :
Code:
1 2 3 4
| function custom_function(){
$tab = $_POST['tab'];
} |