问题描述
我是 laravel 的新手,我想对用控制器编写的函数进行 ajax 调用.我做了以下但没有工作.
在视图中:
我的控制器位于 app/controllers/DashBoardController.php在 DashBoardController.php 里面我有
我的问题是如何从页面加载视图到我的 DashBoardController.php 中的函数进行 ajax 调用?谢谢.
在你的 routes.php
文件中添加
然后使用您的 ajax 调用将数据发送到 /orderdata
数据将传递到 DashBoardController
中的 OrderData
方法p>
所以你的 ajax 调用会变成
如果你想访问数据,你需要像这样将它添加到你的方法中
并更新您的路线
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 :
My Controller which is located inside app/controllers/DashBoardController.php and inside DashBoardController.php I have
My Question is how can I make an ajax call from view on page load to a function inside my DashBoardController.php ?? Thanks.
In your routes.php
file add
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
If you want to access the data you will need to add that into your method like so
And update your route to
这篇关于Laravel Ajax 调用控制器中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!