简体   繁体   English

无法在我的PHP代码中运行JavaScript

[英]Can't run JavaScript in my PHP code

So I'm trying to run some JavaScript code using PHP by echoing it. 所以我试图通过回显它来使用PHP运行一些JavaScript代码。 The issues I'm having is that it's just printing the JavaScript code onto the webpage instead of running it. 我遇到的问题是,它只是将JavaScript代码打印到网页上而不是运行它。 The file itself is a PHP file. 该文件本身是一个PHP文件。 Here is a snippet of my code that is causing me issues: 这是导致我出现问题的代码片段:

<?php 

                $file = file('locations.csv');
                foreach($file as $k)
                    $csv[] = explode(',', $k);


                echo '

                <script>
                var map, heatmap;

                    // Initialize and add the map
                    function initMap() {
                    // The location of Uluru
                    var uluru = {lat: -27.469644, lng: 153.025245};

                    // The map, centered at Uluru
                    map = new google.maps.Map(

                      document.getElementById(\'map\'), {zoom: 16, center: uluru});
                    // The marker, positioned at Uluru
                    //var marker = new google.maps.Marker({position: uluru, map: map});
                    heatmap = new google.maps.visualization.HeatmapLayer({
                      data: getPoints(),
                      map: map
                    });

                    }


                    function toggleHeatmap() {
                        heatmap.setMap(heatmap.getMap() ? null : map);
                    }
                    function changeGradient() {
                    var gradient = [
                      \'rgba(0, 255, 255, 0)\',
                      \'rgba(0, 255, 255, 1)\',
                      \'rgba(0, 191, 255, 1)\',
                      \'rgba(0, 127, 255, 1)\',
                      \'rgba(0, 63, 255, 1)\',
                      \'rgba(0, 0, 255, 1)\',
                      \'rgba(0, 0, 223, 1)\',
                      \'rgba(0, 0, 191, 1)\',
                      \'rgba(0, 0, 159, 1)\',
                      \'rgba(0, 0, 127, 1)\',
                      \'rgba(63, 0, 91, 1)\',
                      \'rgba(127, 0, 63, 1)\',
                      \'rgba(191, 0, 31, 1)\',
                      \'rgba(255, 0, 0, 1)\'
                    ]
                        heatmap.set(\'gradient\', heatmap.get(\'gradient\') ? null : gradient);
                    }
                    function changeRadius() {
                        heatmap.set(\'radius\', heatmap.get(\'radius\') ? null : 20);
                    }

                    function changeOpacity() {
                        heatmap.set(\'opacity\', heatmap.get(\'opacity\') ? null : 0.2);
                    }

                    function getPoints() {
                        return [



                new google.maps.LatLng('.$csv[1][0].', '.$csv[1][1].'),

                new google.maps.LatLng(-27.469628, 153.025231),
                ];
                }
                </script>

                ';

                ?>

Here is what it outputs: 它输出的是:

代码截图

I'm at a loss here, no idea whats causing the issues. 我在这里不知所措,不知道是什么导致了问题。

I fixed it! 我修好了它! Turns out it was because I was running the file directly and not through the XAMPP server. 原来是因为我直接而不是通过XAMPP服务器运行文件。 Im a moron, Sorry about the wast of time guys! 我是个白痴,很抱歉浪费时间! and thankyou for all of the suggestions 并感谢您的所有建议

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM