这是我的控制者:
public function getIndex()
{
$val = Input::get('search');
if (isset($val)) {
$person = Person::where('last_name', 'LIKE', "%$val%")->orderBy('last_name','ASC')->paginate(15);
return Response::json($person);
}
$allowed = array('first_name', 'last_name', 'father_name');
$sort = in_array(Input::get('sort'), $allowed) ? Input::get('sort') : 'last_name';
$order = Input::get('order') ? Input::get('order') : 'ASC';
$person = Person::orderBy($sort,$order)->paginate(15);
$this->layout->content = View::make('hello')->with('person',$person);
}
我的观点
... @foreach ($person as $keys => $values)
<tr class="info">
<td>{{ $values->first_name }}</td>
<td>{{ $values->last_name }}</td>
<td>{{ $values->father_name }}</td>
</tr>
@endforeach
</table>
<div class="footer">
<div class="search">
<div class="img"></div>
<div class="txt">
{{ Form::open(['url' => 'login']) }}
{{ Form::text("search","", ["placeholder"=>"جستجو..."]); }}
{{ Form::close() }}
</div>
</div> ...
我的ajax
$(".search input").on('keyup',function(){
val = $(this).val();
if(val.length>2){
$.ajax({
url: "dashboard/index",
type: 'GET',
data: $(this).serialize(),
success: function(data){
$(".info").remove();
$.each(data.data,function(index,item){
$(".menu").append(
"<tr class=info>"+
"<td>"+item.first_name+"</td>"+
"<td>"+item.last_name+"</td>"+
"<td>"+item.father_name+"</td>"+
"</tr>"
)
});
},
error: function(){
console.log("error");
}
});
}
当我搜索这个附加到“info”类时,但分页不起作用 因为使用这种方法,搜索变量不在url中 所以当我点击下一页时,它会进入默认分页,而不是ajax搜索
请帮帮我