Here is the JavaScript code:
<script>
var cars = ["Saab", "Volvo", "BMW"];
$.ajax({
type: "POST",
url: "yep.php",
data: { 'cars' : cars},
success: function() {
alert("Success");
}
});
</script>
Here is the PHP code:
<?php
$myArray = $_POST['cars'];
var_dump($myArray);
?>`
It is displaying success message, so it means array was passed to php then it shows:
Notice: Undefined index: cars in C:\xampp\htdocs\project\yep.php on line 18
NULL
Why is it returning null for array?
$_POST? maybe your js array is never postedif(isset($_POST['cars'])){ $myArray = $_POST['cars']; var_dump($myArray); die;}