Skip to content
Advertisement

Laravel Ajax Call to a function in controller

I am new to laravel and I want to make an ajax call to a function written in controller. I have done the following but not working.

In View :

JavaScript

My Controller which is located inside app/controllers/DashBoardController.php and inside DashBoardController.php I have

JavaScript

My Question is how can I make an ajax call from view on page load to a function inside my DashBoardController.php ?? Thanks.

Advertisement

Answer

In your routes.php file add

JavaScript

Then use your ajax call to send data to /orderdata the data will be passed through to your OrderData method in the DashBoardController

So your ajax call would become

JavaScript

If you want to access the data you will need to add that into your method like so

JavaScript

And update your route to

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement