如何在laravel中从JavaScript调用PHP变量
How to call a PHP variable from JavaScript in laravel?
我试图将服务的经度和纬度传递给生成谷歌地图的脚本。这是我的代码:
叶片<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代码。我该怎么修理它?
在经度和纬度之后有三个}}}。我认为经度应该是}},纬度应该是}})
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}}},
你应该做
center: new google.maps.LatLng({{$servicio->Longitud}}, {{$servicio->Latitud}},
如果您使用{{{
三个花括号}}}
而不是{{
两个}}
,那么您的输出将被转义,尖括号将被转换为HTML实体。
你可以在这里阅读更多关于使用Blade模板引擎回调数据的信息:http://laravel.com/docs/templates#other-blade-control-structures
相关文章:
- 调用php数组中的JS函数
- 如何使用javascript调用Php文件
- 使用ajax用jquery调用php函数
- 如何使用OnClick事件通过参数调用来调用PHP函数
- php javascript代码从javascript调用php函数
- 在javascript中调用PHP变量
- 如何从jQuery调用PHP函数
- 从Javascript函数调用PHP函数
- 如何使用javascript验证表单中的数据,然后调用php页面
- 在Javascript中调用PHP数据库变量
- 通过Javascript调用php文件
- 使用ajax从javascript/jquery调用php函数
- 阿贾克斯赢得了't调用PHP文件
- 使用AJAX在单独的文件中调用php函数
- 使用ajax/javascript调用php函数
- 使用javascript中的相同代码为REST服务调用php函数
- Ajax调用PHP失败,ASP正常工作.NET
- 通过 AJAX 调用 PHP 文件,将 $_GET 变量传递到 MySQL 查询中,然后回显到响应中
- Codeigniter :通过 AJAX 调用 php 脚本时路由不起作用
- 在 HTML 代码中调用 PHP 函数,在 PHP echo 语句中