【问题标题】:Ajax call effect Laravel View paginationAjax 调用效果 Laravel 查看分页
【发布时间】:2018-03-04 18:48:41
【问题描述】:

我有一个 Laravel 项目,它在 userlist.blade.php 中显示用户列表,它工作正常,但我使用选择字段将分页限制为不同的值,并且在 Stackoverflow 中的 Nitish Kumar 的帮助下,我能够获取从选择字段中选择的值,但我尝试知道如何获取该值以影响当前分页,但我无法理解事情是如何工作的而且我用来显示用户增量编号的循环中的索引不起作用很好的分页,所以我真的需要帮助来了解事情是如何运作的。请问?

userlist.blade.php https://codeshare.io/2KoB4X

用户控制器 https://codeshare.io/G8rzjB

Script.js https://codeshare.io/5o0pWM

路线 https://codeshare.io/a3opmm

编辑 1: 我在下面的链接中查找的示例是数据表,您可以在其中选择显示条目数以在表中显示结果 https://adminlte.io/themes/AdminLTE/pages/tables/data.html

【问题讨论】:

  • 寻求调试帮助的问题(“为什么这段代码不起作用?”)必须包括所需的行为、特定的问题或错误以及在问题本身中重现它所需的最短代码.
  • 我建议使用Yajra Datatable package,它允许您在服务器端处理中使用jQuery datatble。它将解决动态分页的问题,并将在您的用户列表中添加更多功能。
  • @apokryfos 我的问题是如何使用 select 控制分页以在 table par 页面中显示有限数量的用户。
  • @ManishVerma 谢谢我稍后会测试这个,因为我需要添加更多内容,但我现在希望我能找到我的代码的答案

标签: php ajax laravel laravel-5


【解决方案1】:

这是我当前的代码

$(document).ready(function() {
  $('#issueinput5').on('change', function() {
    $.ajax({
        url:'/lists/user',
        method:'POST',
        headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') },
        data:{'pageinateData':$('#issueinput5').val(),},
        success:function(d){
          console.log(d)
        }
   });
  });
});
<div class="form-group col-md-5">
    <div class="col-md-1">Show</div>
    <div class="col-md-2"><select id="issueinput5" name="priority" class="form-control" 
    data-toggle="tooltip" data-trigger="hover" data-placement="top" data-title="Priority">
				  <option value="1">1</option>
					<option value="2">2</option>
					<option value="3">3</option>
    </select></div>
    <div class="col-md-1">entries</div>
</div>
<div class="table-responsive pl-1 pr-1">
    <table class="table table-bordered mb-0">
        <thead>
            <tr>
                <th>#</th>
                <th>Full Name</th>
                <th>Username</th>
                <th>Email</th>
                <th>User Type</th>
                <th>Actions</th>
            </tr>
        </thead>
        <tbody>
            @foreach ($users as $user)
            <tr>
                <th scope="row">{{ $loop->index + 1 }}</th>
                <td>{{ $user->fullname }}</td>
                <td>{{ $user->username }}</td>
                <td>{{ $user->email }}</td>
                <td>
                    @foreach( $roles as $role ) {{ $user->role_id == $role->id ? $role->name : ''}}                         @endforeach
                </td>
                <td>
                    <a href="{{ route('dUseInfo', [$user->id]) }}"><button type="button" 
                    class="btn mr-0 mb-0 btn-outline-primary btn-sm"><i class="icon-settings2"></i>                         </button></a>
                    <button type="button" class="btn mr-0 mb-0 btn-outline-primary btn-sm" 
                    data-toggle="modal" data-target="#iconModal" data-user-id="{{ $user->id }}">
                    <i class="icon-trash3"></i></button>
                </td>
            </tr>
            @endforeach
        </tbody>
    </table>
</div>

【讨论】:

    猜你喜欢
    • 2016-11-21
    • 1970-01-01
    • 2020-12-31
    • 2017-04-29
    • 2014-09-12
    • 2016-11-30
    • 2018-01-17
    • 2018-07-29
    • 2016-01-05
    相关资源
    最近更新 更多