<small id='mR9fb'></small><noframes id='mR9fb'>

      <i id='mR9fb'><tr id='mR9fb'><dt id='mR9fb'><q id='mR9fb'><span id='mR9fb'><b id='mR9fb'><form id='mR9fb'><ins id='mR9fb'></ins><ul id='mR9fb'></ul><sub id='mR9fb'></sub></form><legend id='mR9fb'></legend><bdo id='mR9fb'><pre id='mR9fb'><center id='mR9fb'></center></pre></bdo></b><th id='mR9fb'></th></span></q></dt></tr></i><div id='mR9fb'><tfoot id='mR9fb'></tfoot><dl id='mR9fb'><fieldset id='mR9fb'></fieldset></dl></div>

        <bdo id='mR9fb'></bdo><ul id='mR9fb'></ul>
      <tfoot id='mR9fb'></tfoot>
    1. <legend id='mR9fb'><style id='mR9fb'><dir id='mR9fb'><q id='mR9fb'></q></dir></style></legend>
    2. Laravel Ajax 调用控制器中的函数

      时间:2023-10-31
          <bdo id='wF4CB'></bdo><ul id='wF4CB'></ul>
              <legend id='wF4CB'><style id='wF4CB'><dir id='wF4CB'><q id='wF4CB'></q></dir></style></legend>

            1. <small id='wF4CB'></small><noframes id='wF4CB'>

                <tbody id='wF4CB'></tbody>

                <i id='wF4CB'><tr id='wF4CB'><dt id='wF4CB'><q id='wF4CB'><span id='wF4CB'><b id='wF4CB'><form id='wF4CB'><ins id='wF4CB'></ins><ul id='wF4CB'></ul><sub id='wF4CB'></sub></form><legend id='wF4CB'></legend><bdo id='wF4CB'><pre id='wF4CB'><center id='wF4CB'></center></pre></bdo></b><th id='wF4CB'></th></span></q></dt></tr></i><div id='wF4CB'><tfoot id='wF4CB'></tfoot><dl id='wF4CB'><fieldset id='wF4CB'></fieldset></dl></div>
              1. <tfoot id='wF4CB'></tfoot>
                本文介绍了Laravel Ajax 调用控制器中的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我是 laravel 的新手,我想对用控制器编写的函数进行 ajax 调用.我做了以下但没有工作.

                在视图中:

                $.ajax({类型:POST",url: 'OrderData',//不确定在此处添加什么作为 URL数据:{ id:7 }}).done(函数(味精){警报(味精);});

                我的控制器位于 app/controllers/DashBoardController.php在 DashBoardController.php 里面我有

                class DashBoardController 扩展 BaseController {公共函数 DashView(){返回视图::make('dashboard');}public function OrderData(){//这是我想从 ajax 调用的函数返回我在";}}

                我的问题是如何从页面加载视图到我的 DashBoardController.php 中的函数进行 ajax 调用?谢谢.

                解决方案

                在你的 routes.php 文件中添加

                Route::post('/orderdata', 'DashBoardController@OrderData');

                然后使用您的 ajax 调用将数据发送到 /orderdata 数据将传递到 DashBoardController 中的 OrderData 方法p>

                所以你的 ajax 调用会变成

                $.ajax({类型:POST",url: '/orderdata',//这是我更新的数据:{ id:7 }}).done(函数(味精){警报(味精);});

                如果你想访问数据,你需要像这样将它添加到你的方法中

                class DashBoardController 扩展 BaseController {公共函数 DashView(){返回视图::make('dashboard');}public function OrderData($postData){//这是我想从 ajax 调用的函数//用那个帖子数据做一些很棒的事情返回我在";}}

                并更新您的路线

                Route::post('/orderdata/{postdata}', 'DashBoardController@OrderData')

                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 :

                $.ajax({
                    type: "POST",
                    url: 'OrderData', // Not sure what to add as URL here
                    data: { id: 7 }
                }).done(function( msg ) {
                    alert( msg );
                });
                

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

                class DashBoardController extends BaseController {
                    public function DashView(){
                        return View::make('dashboard');
                    }
                
                    public function OrderData(){ // This is the function which I want to call from ajax
                        return "I am in";
                    }
                }
                

                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

                Route::post('/orderdata', 'DashBoardController@OrderData');
                

                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

                $.ajax({
                    type: "POST",
                    url: '/orderdata', // This is what I have updated
                    data: { id: 7 }
                }).done(function( msg ) {
                    alert( msg );
                });
                

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

                class DashBoardController extends BaseController {
                    public function DashView(){
                        return View::make('dashboard');
                    }
                
                    public function OrderData($postData){ // This is the function which I want to call from ajax
                        //do something awesome with that post data 
                        return "I am in";
                    }
                }
                

                And update your route to

                Route::post('/orderdata/{postdata}', 'DashBoardController@OrderData')
                

                这篇关于Laravel Ajax 调用控制器中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Facebook 使用 Sentry 登录,用户 [email] 需要密码,没有给出 下一篇:Laravel 邮件密件抄送

                相关文章

                <tfoot id='MlVen'></tfoot>

                1. <i id='MlVen'><tr id='MlVen'><dt id='MlVen'><q id='MlVen'><span id='MlVen'><b id='MlVen'><form id='MlVen'><ins id='MlVen'></ins><ul id='MlVen'></ul><sub id='MlVen'></sub></form><legend id='MlVen'></legend><bdo id='MlVen'><pre id='MlVen'><center id='MlVen'></center></pre></bdo></b><th id='MlVen'></th></span></q></dt></tr></i><div id='MlVen'><tfoot id='MlVen'></tfoot><dl id='MlVen'><fieldset id='MlVen'></fieldset></dl></div>
                  <legend id='MlVen'><style id='MlVen'><dir id='MlVen'><q id='MlVen'></q></dir></style></legend>
                  1. <small id='MlVen'></small><noframes id='MlVen'>

                    • <bdo id='MlVen'></bdo><ul id='MlVen'></ul>