Hello am trying to pass an array from my JS script file to another file called serverSide.php so i can print the array in that file and do something with it , am having no issue sending the data and getting a response using the AJAX/JSON the problem i am getting "Notice: Undefined index: theArray in C:\xampp\htdocs\Ajax test\serverSide.php on line 2" when i try to print_r the array i sent ?
**Here is my JS code **
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script
src="https://code.jquery.com/jquery-3.5.1.min.js"
integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0="
crossorigin="anonymous"></script>
</head>
<body>
<h1>Testing AJAX techniques</h1>
<script>
let myArray = [1,2,3];
console.log(myArray);
let myArray1 = JSON.stringify(myArray);
console.log(myArray1);
$.post({
method: 'POST',
url: 'serverSide.php',
data: {theArray: myArray1},
success: function(res) {
console.log(res);
}
})
</script>
</body>
</html>
And this is the serverSide.php file code where i try to print the array
<?php
$test = json_decode($_POST['theArray']);
print_r($test);
?>
Thank you for any help