[英]Can't run JavaScript in my PHP code
所以我试图通过回显它来使用PHP运行一些JavaScript代码。 我遇到的问题是,它只是将JavaScript代码打印到网页上而不是运行它。 该文件本身是一个PHP文件。 这是导致我出现问题的代码片段:
<?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>
';
?>
它输出的是:
我在这里不知所措,不知道是什么导致了问题。
我修好了它! 原来是因为我直接而不是通过XAMPP服务器运行文件。 我是个白痴,很抱歉浪费时间! 并感谢您的所有建议
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.