当我通过php artisan服务器运行此代码时,它看起来不错,但是当我想使用apache时,有404响应。但从一开始。以下是代码的片段:
的Ajax:
$('.item_traveler').select2({
placeholder: 'Wpisz nazwisko podróżnego',
language: "pt-PL",
"language": {
"noResults": function(){
return "Nie znaleziono podróżnego";
},
"searching": function(){
return "Szukam w bazie podróżnych...";
}
},
ajax: {
url: '/autocomplete-ajax-traveler',
dataType: 'json',
delay: 250,
processResults: function (data) {
return {
results: $.map(data, function (item) {
return {
text: item.lastname+" "+ item.firstname+" | "+item.email+" | "+ item.city+", ul."+ item.address_street,
id: item.id
}
})
};
},
cache: true
}
});
路由:
Route::get('/autocomplete-ajax-traveler', 'AutocompleteController@dataAjax_traveler');
控制器:
public function dataAjax_traveler(Request $request)
{
$data = [];
if($request->has('q')){
$search = $request->q;
$data = DB::table("travelers")
->select("id","lastname","firstname","email","city","address_street")
->where('lastname','LIKE',"%$search%")
->get();
}
return response()->json($data);
}
我的.htaccess文件包含:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
我正在研究它5天而没有结果。请帮忙
答案 0 :(得分:1)
关于apache, 你必须提供完整的道路。 即
url: localhost/{Project folder name}/public/autocomplete-ajax-traveler
这样请求就会到达您的应用程序。