Home > Mobile >  404 (Not Found) file, request using laravel with jQuery Ajax
404 (Not Found) file, request using laravel with jQuery Ajax

Time:10-05

I'm currently working on a migration from native PHP to laravel.

The issue is when I try to make a request through Jquery Ajax:

console.log("Join Save TOken Func");
  jQuery.ajax({
     type: "POST",
     url: "/app/controllers/router.php",
     data: { controller: 'api_token', action: action, token: Token, token_name: Token_name, expire_date: Expire_date, permissions: Permissions },
     cache: false,
     success: function(r) {
       ...

The console log returns:

POST http://127.0.0.1:8000/app/controllers/router.php 404 (Not Found)

I have this Js file in the directory:

public\assets\js

I had some issues accessing to other paths different to the /public path, and not sure if this problem is related, because my "router" file is located in:

app\controllers\router.php

CodePudding user response:

you can't access the controller manually from file js or blade, you must use routes on folder routes/web.php to access the controller

if you want to access that controller you must declare this on your routes/web.php

use App\Http\Controllers\router;

Route::POST('/router',[router::class,'index']);
//you can replace 'index' with your function name on laravel

and to access that controller with this

http://127.0.0.1:8000/router

in your situation i think you should read this documentation

https://laravel.com/docs/9.x/eloquent-resources

and this

https://laravel.com/docs/9.x/urls#urls-for-named-routes

  • Related