0
我正在構建一個laravel應用程序,我必須在我的應用程序中使用自動完成搜索。PHP Laravel:自動完成搜索404(未找到)
我的路線:
Route::get('/autocomplete',[
'uses'=>'[email protected]',
'as'=>'autocomplete'
]);
我的控制器:
public function autocomplete(Request $request)
{
$item = $request->input(['searchname']);
$results=array();
$queries = DB::table('courses')
->where('name', 'LIKE', '%'.$term.'%')
->take(5)->get();
foreach ($queries as $data) {
$results[]=['id'=>$data->id,'value'=>$data->name];
}
return Response::json($results);
}
我的視圖頁:
{{ Form::open(['action' => ['[email protected]'], 'method' => 'GET']) }}
{{ Form::text('searchname', '', ['id' => 'searchname', 'placeholder' => 'Enter name'])}}
{{ Form::submit('Search', array('class' => 'button expand')) }}
{{ Form::close() }}
<script type="text/javascript">
jQuery(document).ready(function($) {
$('#searchname').autocomplete({
source: "/autocomplete" ,
minlength:1,
autofocus:true,
select:function(event,ui){
$("searchname").val(ui.item.value);
}
});
});
</script>
所以,當我搜索一個項目,而不是讓項目名稱我是在控制檯中出現以下錯誤:
GET http://localhost/autocomplete?term=tree 404 (Not Found)
任何人都可以幫我找到解決方案嗎?