I need to pass valuesArray to php if button is clicked, when anotherButton is clicked, i want to print this array in PHP.
home.js:
button.onclick = function (){
valuesArray = ['a', 'b', 'c']
$.post('index.php', {data: valuesArray});
}
index.php:
<?php
If(isset($_POST['anotherButton'])){
$getData = $_POST['data'];
print_r($getData);
}
?>
If button gets clicked I get
undefined index: data
which should mean that data wasn't passed to PHP.
$.post('index.php', {"data": valuesArray},function(return,result){});
Notice the double quote around "data".
Also may need to json encode valuesArray?
$.post('index.php', valuesArray, function(result) {
// ....
});
Have a look at documentation: https://api.jquery.com/jquery.post/