Necesito pasar la valuesArray de valores a php si se hace clic en el button , cuando se hace clic en anotherButton botón, quiero imprimir esta matriz en PHP.
casa.js:
button.onclick = function (){ valuesArray = ['a', 'b', 'c'] $.post('index.php', {data: valuesArray}); }índice.php:
<?php If(isset($_POST['anotherButton'])){ $getData = $_POST['data']; print_r($getData); } ?>Si se hace clic en el botón, obtengo
índice indefinido: datos
lo que debería significar que data no se pasaron a PHP.
$.post('index.php', {"data": valuesArray},function(return,result){}); Observe las comillas dobles alrededor de "datos".
¿También puede necesitar json codificar valuesArray?
$.post('index.php', valuesArray, function(result) { // .... });Eche un vistazo a la documentación: https://api.jquery.com/jquery.post/