I am executing a somewhat complex code from my point of view. It goes like this: First I am getting a list of numbers from localstorage from another page.
<script>
var data = JSON.parse(localStorage.getItem('key'));
var localData = data.join(", ");
Then I am posting data to PHP code on the same page like this:
$.ajax({
type: 'post',
data: {localData: localData},
dataType: "json",
success: function(result){
console.log(result)
}
});
</script>
And then I want to put the data into a PHP variable and use it like this:
<?php
$user_id = isset($_POST['localData'])?$_POST['localData']:"";
$values = $user_id;
echo $values; ?>
The network inspector reveals the data is posted like this: localData 3, 5, 6, 8, 9
But I can't seem to get the data into the PHP variable and echo it. Please help.