如何在Laravel中从JavaScript调用PHP变量? [英] How to call a PHP variable from JavaScript in laravel?

查看:153
本文介绍了如何在Laravel中从JavaScript调用PHP变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to pass the longitude and latitude of a service to script that generates a google maps. This is my code:

刀片

<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

控制器

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

}

问题是该脚本无法识别代码laravel或php.我该如何解决?

The problem is that the script does not recognize the code laravel or php. How can I fix it?

推荐答案

在这里,您在Longitud和Latitud之后有三个}}}.我认为Longitud应该是}},Latitud应该是}})

Here you've got three }}} after Longitud and Latitud. I believe Longitud should be }} and Latitud should be }})

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

应为:

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

这篇关于如何在Laravel中从JavaScript调用PHP变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆