如何在laravel中从JavaScript调用PHP变量?
我试图将服务的经度和纬度传递给生成google地图的脚本。 这是我的代码: 刀片如何在laravel中从JavaScript调用PHP变量?,javascript,php,laravel-4,Javascript,Php,Laravel 4,我试图将服务的经度和纬度传递给生成google地图的脚本。 这是我的代码: 刀片 <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false"> </script> <script> function initialize() { var mapOptions = { scaleControl:
<script
src="http://maps.googleapis.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false">
</script>
<script>
function initialize() {
var mapOptions = {
scaleControl: true,
center: new google.maps.LatLng({{$servicio->Longitud}}}, {{$servicio->Latitud}}},
zoom:18
};
var map = new google.maps.Map(document.getElementById('map-canvas'),
mapOptions);
var marker = new google.maps.Marker({
map: map,
position: map.getCenter()
});
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map, marker);
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div class="perfiles">
<legend>Detalle de servicio</legend>
<table class="table">
<tr><td>Numero de Orden</td><td>{{$servicio->idServicio}}</td></tr>
<tr><td>Cliente</td><td>{{$servicio->Cliente}}</td></tr>
<tr><td>Fecha Inicio</td><td>{{$servicio->Hora_Inicio}}</td></tr>
</table>
@if($servicio->Completado)
<div id="map-canvas" style="width:650px;height:300px;"></div>
<table>
<tr><td>{{HTML::image($servicio->RutaFoto1, '', array('width' => '300', 'height' => '300'))}}</td><td>{{HTML::image($servicio->RutaFoto2, '', array('width' => '300', 'height' => '300'))}}</td></tr>
<tr><td>{{HTML::image($servicio->RutaFoto3, '', array('width' => '300', 'height' => '300'))}}</td><td>{{HTML::image($servicio->RutaFoto4, '', array('width' => '300', 'height' => '300'))}}</td></tr>
</table>
@endif
问题是脚本无法识别代码laravel或php。我怎样才能修好它呢?这里在Longitud和Latitud之后有三个。我认为Longitud应该是}},Latitud应该是}) 应该是:
center: new google.maps.LatLng({{$servicio->Longitud}}, {{$servicio->Latitud}}),
您应该使用双花括号
{{
和}
或三个花括号{{{{
和}}
。你不应该把一个和另一个混在一起
而不是
center: new google.maps.LatLng({{$servicio->Longitud}}}, {{$servicio->Latitud}}},
你应该这样做
center: new google.maps.LatLng({{$servicio->Longitud}}, {{$servicio->Latitud}},
如果要使用{{{
三个花括号}}
而不是{{{
两个}
,则输出将被转义,角括号将转换为HTML实体
您可以在此处阅读有关使用刀片模板引擎回显数据的更多信息:
center: new google.maps.LatLng({{$servicio->Longitud}}}, {{$servicio->Latitud}}},
center: new google.maps.LatLng({{$servicio->Longitud}}, {{$servicio->Latitud}},