简体   繁体   中英

Laravel Ajax call url to controller

I am new in laravel. I want to create an api using laravel using ajax call. But I request ajax call,url shows invalid server path. Here is my code
My Route file :

Route::get("a/b","AController@c");

My js file :

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){

});

Suppose I am in following urls:

domain.com/dev/lar/public/index.php/c/d

Then I call this ajax , then url will redirect to

domain.com/dev/lar/public/index.php/c/public/index.php/a/b

Here lar is my laravel app folder

** Note I am using NGINX server. My Server Admin do not rewrite this url. That's why I use public/index.php **

You are missing in controller declaration. You have to use backslash at first. For example

Route::get("/a/b","AController@c");

And in your ajax code url should be

var base = "domain.com/dev/lar/public/index.php";
var url = base + "/a/b";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM