在属性列表javascript之后的SyntaxError:missing}

时间:2015-07-31 10:09:23

标签: javascript php google-maps

我收到以下错误。

错误

  在属性列表

之后

SyntaxError:missing}      

内容:Al futaim,贸易公司<br /> M楼36,Saih Shuaib 3    -

PHP代码

$content=$servicecenter->getCompanyName()."<br />".$servicecenter->getAddress()."<br /><button type='button' value='Get Direction' class='button' onclick='closeInfoWindow(),calcRoute()' name='Get Direction'>Get Direction</button>"; 

脚本

var infowindow = new google.maps.InfoWindow({
  content:<?php echo $content; ?>;
});

3 个答案:

答案 0 :(得分:16)

使用json_encode并删除行尾的分号:

content: <?php echo json_encode($content); ?>  /* no ; here! */

答案 1 :(得分:9)

缺少quote的内容,不需要; -

content: '<?php echo $content; ?>'

OR

content: <?php echo json_encode($content); ?>

答案 2 :(得分:3)

var infowindow = new google.maps.InfoWindow({
    content:<?php echo $content; ?>
});

您不能在对象的声明中包含;。如果要分隔属性,请使用,

此外,根据您想要回显的内容,您可能需要在php脚本周围添加"