javascript - 需要将 laravel 中的表中的 id 传递给另一个刀片中的脚本
问题描述
这是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>
我需要在此脚本( single_device.blade.php)中获取此刀片中的 id 值
这是single_device.blade.php
<main class="main">
<div id='map'></div>
</main>
<script>
var device_id = (here i need that id)
</script>
解决方案
- 您可以使用 ajax 请求将 id 存储在会话中,然后在您想要的刀片中调用。
另一种方法是,在 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);
推荐阅读
- python - 如何解决 IndexError:列表索引超出范围
- c# - 如果基类没有构造函数,我可以从类继承吗
- c++ - 如何制作可以缩放和绘制的画布 QWidget?
- python-3.x - 如何在 Python 中实现 QT(质量阈值)聚类?
- haskell - 求叶子总和
- python-3.x - Pytorch:ValueError:预期输入batch_size(32)与目标batch_size(64)匹配
- python - Maya Python Script - os.popen tasklist read 超级慢。更快的方式?
- .net - 找不到文件“C:\cfn\ebdata\source_bundle_final.zip”
- java - 为什么 Oracle 声称 java.util.Random.nextFloat() 生成 2^24 种可能性而不是 2^23?
- react-native - React-Native:按两次按钮只会更新 this.setState