I am trying to send the content of a JavaScript array to a different page using $.post, but it doesn’t work – the coreresponding $_POST is not set…
Can someone explain me what’s wrong ?
Here is the js code, on page 1:
<script type="text/javascript">
var i = sessionStorage.length;
var categoriesTab = [];
for (let j = 0; j < i; j++) {
if (sessionStorage.getItem(sessionStorage.key(j)) == 'active') {
categoriesTab.push(sessionStorage.key(j));
}
}
const liste = document.getElementById('liste');
liste.addEventListener('click', function (event){
event.preventDefault();
if (window.location.href == 'https://dom.fr/page1/'){
$.post(
'page2.php',
{
categoriesActives : categoriesTab
}
)
}
window.location.assign('https://dom.fr/page2/');
});
</script>
The categoriesTab variable is set and everything seems to work.
But when I get to page 2, $_POST is empty… :
<?php
$array = [];
if (isset($_POST['categoriesActives'])) {
$array = $_POST['categoriesActives'];
} else {
$array = ['a', 'z', 'e', 'r'];
}
?>```