我希望通过 Laravel URL 传递数据集。这是我的代码。首先,我将我的数据集传递给 JavaScript,然后调用 URL。
JavaScript 代码:
<script type="text/javascript">
function divClick(roomState, roomCode){
// Your code here
//window.alert(roomCode); //print_output well
//value_url out put as following
//room_detail/{"id":"24","room_code":"H5016","roomState":"UnAvailable","hotelId":"5","roomTypeId":"7","created_at":"-0001-11-30 00:00:00","updated_at":"2015-11-04 06:52:09"}
//call new page
window.location.href ="{{url('room_detail/roomCode')}}";
}
</script>
routes.php文件代码
Route::any('room_detail/{roomDetail}', function() {
return view('pages/room_details/roomMap/single_room_map_detail', compact('roomDetail'));
});
我使用这段代码来打印传递的值。
========view.blade.php========================================
<section class="content">
<div class="row">
<div class="box box-warning">
<div class="gap">
<div class="box-body">
{!! $roomDetail !!}
</div><!-- /.box -->
</div><!-- /.box -->
</div><!-- /.row -->
</div>
</section><!-- /.content -->
当视图被渲染时,我会收到这个错误:
Undefined variable: roomDetail
期望一些专家的帮助,通过 URL 传递此数据集。
window.location.href ="{{url('room_detail/')}} + value_url";
如果需要使用JSON格式,您还需要对变量进行json_decode
处理。 - Tim