最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

php - SyntaxError: missing } after property list javascript - Stack Overflow

programmeradmin4浏览0评论

I am getting the below error.

Error

SyntaxError: missing } after property list

content:Al futaim, trading company<br />Building M, 36, Saih Shuaib 3 —

PHP code

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

Script

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

I am getting the below error.

Error

SyntaxError: missing } after property list

content:Al futaim, trading company<br />Building M, 36, Saih Shuaib 3 —

PHP code

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

Script

var infowindow = new google.maps.InfoWindow({
  content:<?php echo $content; ?>;
});
Share Improve this question edited Apr 1, 2016 at 10:42 Munawir 3,3569 gold badges35 silver badges51 bronze badges asked Jul 31, 2015 at 10:09 Qaisar SattiQaisar Satti 2,7622 gold badges19 silver badges36 bronze badges 3
  • 2 You need to add the quotes (either doulbe or single quotes will do) – Raphioly-San Commented Jul 31, 2015 at 10:12
  • To add some more info: You need to add the quotes (either double or single quotes will do), remove the semicolon after the php closing tag and remember to escape your output (i.e. try addslashes or htmlentities) – Raphioly-San Commented Jul 31, 2015 at 10:18
  • i got error after adding the quotes SyntaxError: unterminated string literal content: – Qaisar Satti Commented Jul 31, 2015 at 10:18
Add a comment  | 

3 Answers 3

Reset to default 16

Use json_encode and delete the semicolon at end of line:

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

Missing the quotes for content and no need of ; -

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

OR

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

You can't have a ; inside an object's declaration. If you want to separate properties, use ,.

Also, depending on what you want to echo there, you might need to add " around the php script.

发布评论

评论列表(0)

  1. 暂无评论