How to pass a PHP array to another PHP page with ajax
<p>I have been looking for this answer without success.
I have three files: index.php, actions.js and devices.php</p>

<p>My index.php have this code:</p>

<pre><code>&lt;?php
        $file = "canvas/interactiveWorkstations/".$roomData['id'].".json";
        if(file_exists($file)){
            $map = "interactiveWorkstation";
            $lines = file($file);
            $nPolygon = $lines[count($lines) - 4];
            $counterPolygon = 0;
            $pos = 4;
            $areas = array();

            while($counterPolygon !== $nPolygon &amp;&amp; $pos &lt; count($lines)){
                $lines[$pos] = json_decode($lines[$pos], true);
                if($counterPolygon !== 0)
                    $lines[$pos] = array_diff_assoc($lines[$pos], $lines[$pos-9]);
                $coords = "";
                foreach($lines[$pos] as $line)
                    foreach($line as $k =&gt; $v)
                        if($k !== "color" &amp;&amp; $v !== -1)
                            $coords .= $v . ", ";
                $coords = trim($coords, ', '); //Delete last space and last comma
                $lines[$pos-3] = trim($lines[$pos-3], '#');
                $areas[trim($lines[$pos-3])] = $coords;
                $counterPolygon++;
                $pos = $pos + 9;
            }
    ?&gt;
        &lt;script&gt;
            var img = document.getElementsByClassName('connection')[0];
            img.setAttribute('usemap', '&lt;?php echo "#".$map; ?&gt;');
            img.insertAdjacentHTML('afterend', '&lt;map name="&lt;?php echo $map; ?&gt;" id="&lt;?php echo $map; ?&gt;"&gt;&lt;/map&gt;');
            var points = &lt;?php echo json_encode($areas);?&gt;;
        &lt;/script&gt;
    &lt;?php
        }
       if($bookingActive) {
echo '&lt;script type="text/javascript"&gt;reloadDevices("'.$workstationName.'","'.$randomKey.'","'.$bookingData['ical_uid'].'",points); initCountdown('.$remainingTime.');&lt;/script&gt;';
}
</code></pre>

<p>At this point I have passed my $areas variable to JS using json_encode, and my functions reloadDevices() and UpdateDevices() receive it correctly because I checked before.</p>

<p>In my actions.js file have this code:</p>

<pre><code>function updateDevices(workstation,randomKey,z,points){
    var parameters = {
            "workstation" : workstation,
            "randomKey" : randomKey,
            "z" : z,
            "points" : points
    };
    $.ajax({
            data:  parameters,
            url:   'workstation/devices.php',
            type:  'post',
            success:  function (response) {
                    $("#devices").html(response);
            }
    });
}
function reloadDevices(workstation,randomKey,z,points) {
    updateDevices(workstation,randomKey,z, points);
    setInterval(function () { updateDevices(workstation,randomKey,z, points); }, 6000);
}
</code></pre>

<p>I do an ajax call to devices.php, but when I wanna get my $_POST['points'] variable is empty.
The part of code from my devices.php where I use this variable:</p>

<pre><code>&lt;?php
$areas = json_decode($_POST['points'], true);
?&gt;
&lt;script&gt;
    var map = document.getElementById('interactiveWorkstation');
    var area = document.getElementById('&lt;?php echo $deviceName; ?&gt;');
    if(!area)
        map.insertAdjacentHTML('beforeend', '&lt;area id="&lt;?php echo $deviceName; ?&gt;" shape="polygon" coords="&lt;?php echo $areas[$deviceName]; ?&gt;" href=\'javascript:createTerminal(&lt;?php echo "\"".$deviceName."\""; ?&gt;, &lt;?php echo "\"".$deviceIp; ?&gt;-&lt;?php echo $randomKey."\""; ?&gt;, &lt;?php echo "\"".$uid."\""; ?&gt;, &lt;?php echo "\"".$deviceName."\""; ?&gt;);\'/&gt;');
&lt;/script&gt;
</code></pre>

<p>Honestly, I can't see the error. If someone helps me appreciate it.
Thanks so much.
Regards.</p>