Answer the question
In order to leave comments, you need to log in
How to pass js array to php variable as string?
There is an array of numbers, let's say [2, 23, 54, 79, 27, 99, 14], which lies in localStorage. I send it like this:
var myArray = JSON.parse(localStorage.myArray);
console.log(myArray);
var data = JSON.stringify(myArray);
$.ajax({
type: 'POST',
url: 'Путь к моему файлу/page-izbranni.php',
dataType: 'json',
cache: false,
data: {checks: data},
success: function(data) {
alert(data)
}
});
<?php $izzz = json_decode($_POST['checks']); ?>
<p><?php echo $izzz; ?></p>
Answer the question
In order to leave comments, you need to log in
<?php $izzz = json_decode($_POST['checks'], true); ?>
<?php echo implode(", ", $izzz); ?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question