【发布时间】:2017-06-06 20:02:27
【问题描述】:
我是 laravel 的新手。我想使用 ajax 调用使用 laravel 创建一个 api。但我请求 ajax 调用,url 显示无效的服务器路径。
这是我的代码
我的路线文件:
Route::get("a/b","AController@c");
我的 js 文件:
var base = "public/index.php";
var url = base + "a/b";
$.ajax({
url : url,
dataType: "json",
timeout: 10000,
error:function(){ alert("Error getting from server") }
}).done(function(resp){
});
假设我在以下网址中:
domain.com/dev/lar/public/index.php/c/d
然后我调用这个 ajax ,然后 url 将重定向到
domain.com/dev/lar/public/index.php/c/public/index.php/a/b
这里 lar 是我的 laravel 应用文件夹
** Note I am using NGINX server. My Server Admin do not rewrite this url. That's why I use public/index.php **
【问题讨论】:
-
试试这个代码 Route::get("/a/b","AController@c");而不是 Route::get("a/b","AController@c");
-
这条路线不起作用,因为我的应用程序文件夹是域之后的许多子文件夹。 ex- domain.com/dev/{laravel 应用文件夹}
-
为什么你使用 domain.com/dev/lar/public/index.php/c/d 而不是 domain.com/dev/lar/public/c/d。你让 index.php 成为目录而不是文件???
-
domain.com/dev/lar/public/c/d 给出 404 错误。给 domain.com/dev/lar/public/index.php/c/d 后,路由正常
标签: javascript php jquery ajax laravel-5