javascript - 如何在 Laravel 中从 JavaScript 调用 PHP 变量?

标签 javascript php laravel-4

我正在尝试将服务的经度和纬度传递给生成谷歌地图的脚本。 这是我的代码:

Blade

<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

Controller

public function doDetail($id){
    $servicio = Servicio::find($id);
    return View::make('detalleservicio', array('servicio' => $servicio));

}

问题是脚本无法识别代码 laravel 或 php。我该如何修复它?

最佳答案

这里在经度和纬度之后有三个 }}}。我相信经度应该是 }},纬度应该是 }})

center: new google.maps.LatLng({{$servicio->Longitud}}}, {{$servicio->Latitud}}},

应该是:

center: new google.maps.LatLng({{$servicio->Longitud}}, {{$servicio->Latitud}}),

关于javascript - 如何在 Laravel 中从 JavaScript 调用 PHP 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23619857/

相关文章:

php - 更多结果 - 更快的查询(在 mysql 中按纬度和经度搜索)

php - 在 PHP 中检测轮数?

Laravel 5 - 仅在特定页面/ Controller (页面特定 Assets )上添加样式表

javascript - 带有屏幕调整大小的 HTML 菜单栏

javascript - 如何将数据(以uri格式)从浏览器拖到其他应用程序

javascript - typeORM 黑名单用户

php - 如何在使用 Doctrine 固定装置时获取数据库中的实体?

php - 我在哪里放置可以显示 Flash 消息的 Laravel 4 辅助函数?

php - 为 Laravel 中的每个 Controller 和方法创建一个路由

javascript - Node.js EasyRTC 视频录制