【问题标题】:Laravel Ajax PaginationLaravel Ajax 分页
【发布时间】:2014-09-12 08:31:15
【问题描述】:

我正在尝试基于复选框单击来获取 ajax 搜索过滤器的分页。每个复选框单击时我的控制器功能:

public function ajaxGetServices(){

    $a_data = Input::all();

    Session::put('a_data',$a_data);
    $i=0;
    if(count($a_data) == 0){

        $temp = User::has('editor')->paginate(4);
        $this->data['editors'] = $temp->toArray();

        if(Auth::user()){
            $this->data['favorited_editors'] = Favorite::where('member_id','=',Auth::user()->id)->get()->toArray();
            $i=1;
        }


    }else{


        $editors = User::with(['editor.credentials','editor.specialties','editor.ratings']);
        $temp=$editors->whereHas('editor', function($q) use ($a_data){
            $q->whereHas('specialties',function($sq) use($a_data){
            $sq->whereIn('specialty',$a_data);
            });
        })->paginate(2);

        //var_dump($temp->toJson()); die();

        $this->data['editors'] = $temp->toArray();
        if(Auth::user()){
            $this->data['favorited_editors'] = Favorite::where('member_id','=',Auth::user()->id)->get()->toArray();
            $i=1;
        }

    }//endelse

    if($i==1){

        return Response::json(array('editors' => $this->data['editors'], 'favorited_editors' => $this->data['favorited_editors']));

    }
    else{
        $this->data['favorited_editors'] = array();
        return Response::json(array('editors' => $this->data['editors'], 'favorited_editors' => $this->data['favorited_editors']));
    }


}

这给了我总页数、当前页、每页、从和到分页字段。现在我需要重新生成分页链接以反映上述结果。请指导我如何去做。此外,如果需要,我可以提供更多代码来澄清我的问题。感谢您的建议。

【问题讨论】:

  • 另外,目前我正在发送 links() 数据以及其他结果。在 ajax 成功函数中,我将分页的 ul 替换为“链接”数据。但是每个链接都有getServices?page=2,但它会抛出`MethodNotAllowedHttpException`

标签: jquery ajax laravel-4 pagination


【解决方案1】:

也许这篇文章会有所帮助 http://www.laravel-tricks.com/tricks/easy-ajax-pagination https://gist.github.com/tobysteward/6163902(完整示例所以我没有提供任何解释)

【讨论】:

    猜你喜欢
    • 2016-11-30
    • 2016-01-05
    • 1970-01-01
    • 2015-11-27
    • 2015-02-01
    • 1970-01-01
    • 2020-05-12
    • 1970-01-01
    • 2015-03-14
    相关资源
    最近更新 更多