我在地图上显示了一些标记。单击时,将显示一个信息窗口。这个窗口包含2个按钮,每个发送ajax请求。问题是,当我向按钮onClick事件发送任何东西(下面的标记参数除外)时,它不起作用。我在HTML页面的第一行得到错误“adminmap.html:1 Uncaught SyntaxError:Unexpected token ILLEGAL”,而不是脚本文件。
function handleButtonApprove(id) {
//error happens here when I send any parameter except marker8(defined below)
//console.log(id);
$(document).ready(function () {
$.ajax({
type: "POST",
url: VERIFY_OBSTACLES_URL,
//data: { markerID:sentID , approved:0 },
success: function (data) {
alert(data);
}
});
});
}
function handleButtonReject() {
$(document).ready(function () {
$.ajax({
type: "POST",
url: VERIFY_OBSTACLES_URL,
//data: { markerID:marker.id , approved:0 },
success: function (data) {
alert(data);
}
});
});
}
function attachInfo(marker8, num) {
//var markerID = marker.get("id");
//console.log(markerID);
var infowindow = new google.maps.InfoWindow({
//Here is the error , if I sent num.toString, num or any string , it does not work. If send marker8.getPosition() for example it works. May I know the reason ?
content: '<div id="info_content">Matab Info</div> <button onclick="handleButtonApprove(' + num.toString() + ')">Verify</button> </br> <button onclick="handleButtonReject()">Remove</button>'
});
google.maps.event.addListener(marker8, 'click', function () {
infowindow.open(marker8.get('map'), marker8);
});
}
答案 0 :(得分:0)
如果要提供(非数字)字符串作为handleButtonApprove()的参数,则必须用引号包装该字符串:
content: '<div id="info_content">Matab Info</div> \
<button onclick="handleButtonApprove(\'' + num.toString() + '\')">\
Verify</button>\
</br> <button onclick="handleButtonReject()">Remove</button>'
但这不是问题所在,因为当您不使用引号时,错误应该是未定义的变量而不是语法错误。究竟是什么num
?