javascript return中的laravel csrf该页面已由于不活动而过期。请刷新,然后重试

时间:2018-08-30 04:30:34

标签: jquery laravel-5

我在表中有一个用于删除数据循环的代码。 可以使用,并且有效。

@foreach ($datasiswa as $a)

<a class="btn btn-info btn-sm" data-toggle="modal" data-target="#aktifMagang{{ $a->id }}"><i class="fa fa-check"></i> Aktifkan Magang</a>
<!-------- start Modal --->
<div id="aktifMagang{{ $a->id }}" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header bg-aqua">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Daftarkan Magang</h4>
            </div>
            <div class="modal-body">
                <form action="{{route('magang.odin.akftikanmagang',['id'=>$a->id])}}" method="POST" class="form-horizontal">
                    {{ csrf_field()}} Aktifkan <strong>{{ $a->user->name }}</strong> sebagai peserta magang ?
                    <input type="hidden" name="siswa_id" value="{{ $a->id }}">
                </form>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Aktifkan</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>
@endforeach

但是结果将使每个数据成为模态。 如果我有100个数据,那么应该有100个模态。

有没有办法使它成为一个模态?

搜索...,我找到了。

@foreach ($datasiswa as $a)
<a class="btn btn-info btn-sm"data-toggle="modal" data-target="#aktifMagang" data-siswaid="{{ $a->id }}"><i class="fa fa-check"></i> Aktifkan Magang
</a><br /> 
@endforeach

然后

<div id="aktifMagang" class="modal fade" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header bg-aqua">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Daftarkan Magang</h4>
            </div>
            <div class="modal-body">
                <form action="{{route('magang.odin.akftikanmagang',['id'=>$a->id])}}" method="POST" class="form-horizontal">
                    Aktifkan <strong class="namasiswa"></strong> sebagai peserta magang ?
                    <input type="hidden" name="siswa_id" value="">
                </form>
            </div>
            <div class="modal-footer">
                <button type="submit" class="btn btn-primary">Aktifkan</button>
                <button type="button" class="btn btn-default" data-dismiss="modal">Batal</button>
            </div>
        </div>
    </div>
</div>

然后添加另一个

<script>
  $('#aktifMagang').on('show.bs.modal', function(event) {
    var button = $(event.relatedTarget) 
    var recipient = button.data('siswaid') 
    var modal = $(this)
    modal.find('.namasiswa').text(namasiswa)
    modal.find('.modal-body input').val(recipient)
  })
</script>

但是 该页面因不活动而过期。请刷新并重试

0 个答案:

没有答案