<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 调用控制器中的函数

      Laravel Ajax Call to a function in controller(Laravel Ajax 调用控制器中的函数)
          <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 调用控制器中的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
                PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
                mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
                Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
                Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
                Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)
                <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>
                      <tbody id='MlVen'></tbody>

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

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