[英]need to pass an id from table in laravel to script in another blade
这是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>
首先,您需要熟悉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>
另一种方法是在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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.