当URL有一个尾部斜杠时,Laravel JQuery AJAX ISSUE

时间:2017-11-10 03:44:23

标签: jquery ajax laravel url

在Laravel中使用 AJAX调用

时出现 404 Not Found 错误

URL

var url = "{{config('app.url')}}/profile/get/";

路线

Route::post('/profile/get','StaffController@show');

当上述URL传递给AJAX调用时,它会抛出 404 Not Found

 $.post(url, {"_token":"{{ csrf_token() }}"}, function( msg ){
    console.log( msg );
  }); 

我有什么遗失的吗?

1 个答案:

答案 0 :(得分:0)

我在laravel上偶然发现了github issue。看起来尾随斜杠与Laravel中的路线不匹配。

当我从URL中删除尾部斜杠时,它就像一个魅力。

但是,当我添加一个带有斜杠的新路线时,它没有帮助。

Route::post('/profile/get/','StaffController@show');

我正在使用 Laravel Framework 5.4.36

另外, Google网站管理员博客指出,某些网站会像对待目录一样处理带有和结束斜杠的网址,而不像文件那样忍受斜杠

http://example.com/foo/ (with trailing slash, conventionally a directory)
http://example.com/foo (without trailing slash, conventionally a file)

see here