R
R
Roman Savitsky2016-04-23 18:44:49
PHP
Roman Savitsky, 2016-04-23 18:44:49

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)
                    }
                });

In the page-izbranni.php file, I accept it this way:
<?php $izzz = json_decode($_POST['checks']); ?>
        <p><?php echo $izzz; ?></p>

It is necessary that in php there are numbers in the form of a string 2, 23, 54, 79, 27, 99, 14
Nothing comes up, what's the problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kuznetsov, 2016-04-23
@PRC

<?php $izzz = json_decode($_POST['checks'], true); ?>
<?php echo implode(", ", $izzz); ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question