【问题标题】:Laravel. AJAX does not work on apache拉拉维尔。 AJAX 不适用于 apache
【发布时间】:2018-11-13 11:54:30
【问题描述】:

当我通过 php artisan 服务器运行这段代码时,它看起来不错,但是当我想使用 apache 时,会出现 404 响应。但从一开始。以下是代码片段:

阿贾克斯:

        $('.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);
}

当我使用 php artisan serve 时,它​​看起来像:

当我使用 apache 时,它​​看起来像:

我的 .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 天,但没有结果。请帮忙

【问题讨论】:

  • 我认为端口号不匹配
  • 尝试在您的 apache URL 上添加 /public 并重试。
  • @jithesh-kt。恐怕这行不通。

标签: ajax laravel apache


【解决方案1】:

在 Apache 上, 你必须给出完整的路径。 即。

url: localhost/{Project folder name}/public/autocomplete-ajax-traveler

这样请求将到达您的应用程序。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 2014-09-18
  • 1970-01-01
  • 1970-01-01
  • 2018-05-10
  • 2021-07-19
相关资源
最近更新 更多