javascript - 无法在我的 PHP 代码中运行 JavaScript
问题描述
所以我试图通过回显它来使用 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 服务器。我是个白痴,抱歉浪费了大家的时间!谢谢你的所有建议
推荐阅读
- javascript - 页面重新加载后在url中添加锚点并在JS中显示隐藏部分
- apache-flink - Flink kinesis 连接器因守护程序异常而崩溃
- vba - 无法使我的脚本异步工作
- python - 给定参数值的 Lambdify/Evaluate
- app-store - 无法将开发者添加到 AppStore Connect
- sql - 如果记录不存在,则将数据从一个数据库插入另一个数据库
- subdomain - 使用指定的端口访问 NAT 后面的子域
- mysql - 连接字符串不正确。请访问门户以获取参考
- javascript - 访问数组 javascript [zapier] 的成员
- vb.net - 删除 datagridview vb.net 中的组合重复项。网