I am trying to send this array from javascript to PHP, but I keep getting Undefined index: list in on line 3. This error is coming from in the php file.
I am going to provide to whole code including the html, javascript, and php.
Here is the HTML code.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script type= "text/javascript" src = "js.js"></script>
</head>
<body>
<form class = "wall" action="phpf.php" method="post">
<label>What is your name</label>
<input type="text" name ="name" />
<input type = "submit" value = "Submit Order" />
</form>
</body>
Here is the Javascript code
$(document).ready(function () {
var list = [34, 56, 23, 90, 43, 58];
$.ajax({
type: "POST",
url: "phpf.php",
data: {'list': JSON.stringify(list)},
cache: false,
success: function (response) {
console.log("This is the list", list);
}
});
})
Here is where I am receiving it in PHP
<?php
$list = json_decode($_POST['list']);
echo "This is the new list".$list;
?>
I was hooping that someone could me please.