SyntaxError: missing} after javascript property list

I get the following error.

Mistake

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; ?>; }); 
+7
javascript php google-maps
source share
3 answers

Use json_encode and remove the semicolon at the end of the line:

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

There is no quote for the content and is not required ; -

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

OR

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

An object declaration cannot be ; . If you want to separate properties, use,.

In addition, depending on what you want to respond to, you may need to add a " script around PHP " .

+3
source share

All Articles