我希望通过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传递此数据集。
答案 0 :(得分:2)
您的路线需要如下所示(注意函数调用中的变量):
Route::any('room_detail/{roomDetail}', function($roomDetail) {
return view('pages/room_details/roomMap/single_room_map_detail', compact('roomDetail'));
});
你还需要将变量正确地传递给url:
window.location.href = "{{url('room_detail')}}" + "/" + roomCode; // maybe you can discard the slash after room_detail.