这是 single.blade.php
@foreach($device_property_List as $val)
<tr>
<td>{{$val -> properties-> number_plate}}</td>
<td>
<input type="hidden" value="{{$val -> id}}"> <-this value need to pass in single_device.blade.php by ajax
<input type="submit" id="{{$val -> id}}" class="btn btn-success btn-sm live" value="Live">
</td>
</tr>
@endforeach
这是此页面( single.blade.php )的脚本,用于将ID发送到另一个页面( single_device.blade.php )
这是 single.blade.php
<script type="text/javascript">
$(document).on('click', '.live', function(){
var id = $(this).attr('id');
$.ajax({
window.location.href ="{{url('single_device')}} ->with (id)";
})
});
</script>
我需要在此脚本中的此刀片中获取id值( single_device.blade.php )
这是 single_device.blade.php
<main class="main">
<div id='map'></div>
</main>
<script>
var device_id = (here i need that id)
</script>
答案 0 :(得分:0)
首先,您需要熟悉ajax是什么
我认为链接可以解决您的问题。
<a href="{{route('single_device', ['id' => 1])}}">Some Text</a>
或
<script>
$(document).ready(function(){
$(".live").click(function(){
$.ajax({
/* the route pointing to the update function */
url: '/',
type: 'POST',
data: {id:$(this).val()},
dataType: 'JSON',
/* remind that 'data' is the response of the Controller */
success: function (data) {
}
});
});
});
</script>
答案 1 :(得分:0)
另一种方法是在URL中使用加密和解密的ID。
use Illuminate\Support\Facades\Crypt;
$key = Crypt::encrypt($key);
<a href="{{route('single_device', ['id' => $key])}}">Some Text</a>
$key = Crypt::decrypt($key);