V
V
Viktor Volkov2018-05-20 10:04:38
PHP
Viktor Volkov, 2018-05-20 10:04:38

How to pass an array from JS to PHP?

I know, the topic is beaten ... and even so, I could not find a solution ....
on the client side I have such an array and pass it to PHP:

var res = [
            32,
            32,
            132,
            13.2,
            118.8,
            'слово на русском'
        ];

        var  arr = JSON.stringify(res);
        alert(arr);


        location.href='http://INSPECTION/CALCMARsaveOk/'+ arr;

on the server side I accept it:
echo '<pre>';
        var_dump($arr);
        var_dump(json_decode($arr));

result:
string(119) "[32,32,132,13.2,118.8,%22%D1%81%D0%BB%D0%BE%D0%B2%D0%BE%20%D0%BD%D0%B0%20 %D1%80%D1%83%D1%81%D1%81%D0%BA%D0%BE%D0%BC%22]"
NULL
client encoding:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
...

php is also in UTF-8.
I need Cyrillic, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anatoly Medvedev, 2018-05-20
@VGVolkov

https://secure.php.net/manual/ru/function.urldecode.php
In general, it is more correct to pass it as a parameter, for example:

var res = [
            32,
            32,           
            132,
            13.2,
            118.8,
            'слово на русском'
        ];
        var  arr = JSON.stringify(res);
        location.href='http://INSPECTION/CALCMARsaveOk/?arr='+ arr;

var_dump($_GET);

V
Viktor Volkov, 2018-05-20
@VGVolkov

"In general, it is more correct to betray as a parameter, for example:"

I have a slightly peculiar, self-made router) I don’t even want to rummage now) urlencode made my day!)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question