未捕获的SyntaxError: Unexpected token
Uncaught SyntaxError: Unexpected token �
m恼人从这个错误/////m试图从数据库中获取纬度和纬度,并根据他们,我想在地图上显示标记.....这里我遇到了错误....请帮助我....谢谢我的代码是:
// Ban Jelacic Square - City Center
var map;
var center = new google.maps.LatLng(-34.397, 150.644);
var geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow();
var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();
function init() {
var mapOptions = {
zoom: 8,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('directions_panel'));
/* // Detect user location
if(navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var userLocation = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
geocoder.geocode( { 'latLng': userLocation }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
document.getElementById('start').value = results[0].formatted_address;
}
});
}, function() {
alert('Geolocation is supported, but it failed');
});
}
*/
makeRequest('get_location.php', function(data) {
var data = JSON.parse(data.responseText);
for (var i = 0; i < data.length; i++) {
displayLocation(data[i]);
}
});
}
function displayLocation(location) {
var content = '<div class="infoWindow"><strong>' + location.name + '</strong>'
+ '<br/>' + location.address
+ '<br/>' + location.description + '</div>';
if (parseInt(location.lat) == 0) {
geocoder.geocode( { 'address': location.address }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location,
title: location.name
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(content);
infowindow.open(map,marker);
});
}
});
} else {
var position = new google.maps.LatLng(parseFloat(location.lat), parseFloat(location.lng));
var marker = new google.maps.Marker({
map: map,
position: position,
title: location.name
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(content);
infowindow.open(map,marker);
});
}
}
function makeRequest(url, callback) {
var request;
if (window.XMLHttpRequest) {
request = new XMLHttpRequest(); // IE7+, Firefox, Chrome, Opera, Safari
} else {
request = new ActiveXObject("Microsoft.XMLHTTP"); // IE6, IE5
}
request.onreadystatechange = function() {
if (request.readyState == 4 && request.status == 200) {
callback(request);
}
}
request.open("GET", url, true);
request.send();
}
/////get_location.php文件
setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);$sth = $db->query("SELECT * FROM data");$locations = $sth->fetchAll();Echo json_encode($locations);} catch(异常$e) {echo $ e -> getMessage ();}div ?>试试这个,看看是否有帮助:
<?php
require 'config1.php';
function removeNonUTF8( &$value, $key ) {
$regex = <<<'END'
/
(
(?: ['x00-'x7F]
| ['xC0-'xDF]['x80-'xBF]
| ['xE0-'xEF]['x80-'xBF]{2}
| ['xF0-'xF7]['x80-'xBF]{3}
)+ # ...one or more times
)
| . # anything else
/x
END;
$value = preg_replace( $regex, '$1', $value );
}
try {
$db = new PDO($dsn, $uname, $pass);
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
$sth = $db->query("SELECT * FROM data");
$locations = $sth->fetchAll();
foreach( $locations as $location ) {
array_walk( $location, 'removeNonUTF8' );
}
echo json_encode( $locations );
} catch (Exception $e) {
echo $e->getMessage();
}
?>
同样,如果这不起作用,你可以打印你的$locations
变量,这样我们可以看到结构。
相关文章:
- ReactJS Unexpected Token ) on Safari only
- Ajax错误:SyntaxError: Unexpected token <错误
- ajaxt weird error: Uncaught SyntaxError: Unexpected token if
- index.php:13 Uncaught SyntaxError: Unexpected token: Ci中的错误消
- 接收错误"Uncaught SyntaxError: Unexpected token "用Shin
- React JS应用程序- Uncaught SyntaxError: Unexpected token <
- nodeJS syntaxError: unexpected token this
- 尝试使用标记的模板字符串给出'Uncaught SyntaxError: Unexpected token
- 未捕获的SyntaxError: Unexpected token <在JQuery UI地图插件?在本地工作,而不是在
- Javascript for循环返回“Uncaught SyntaxError: Unexpected Token <&
- 在尝试动态删除表行时,得到Uncaught SyntaxError: Unexpected token}
- 未捕获的SyntaxError: Unexpected token <谷歌分析谷歌标签管理器
- 为什么json返回"Unexpected Token:"当使用$.ajax()时,我的json格式正
- 查找&;Unexpected token;&;的原因/行Express-JS中的错误
- 内联onclick事件返回"Uncaught SyntaxError: Unexpected token (&
- 未捕获的SyntaxError: Unexpected token <在Javascript中调用外部web服务时出现错
- 来自UglifyJs的错误:SyntaxError: Unexpected token: operator (>)
- 未捕获的SyntaxError: Unexpected token ILLEGAL (PHP &Javascript)
- 未捕获的SyntaxError: Unexpected token: Can't resolve
- Uncaught SyntaxError: Unexpected token)在解析JSON字符串时