weixin_33725722 2017-06-28 23:28 采纳率: 0%
浏览 143

Laravel使用Ajax调用

In my blade I use an ajax call to call a route. In my controller I am returning a different view. However, the view does not change. I am wondering if I need to change the view differently because I am using an ajax call that needs a return of success or not.

Here is my ajax code in my blade

 $('#btnAnalyze').click(function(){
               var text = $('#cv').val();
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });
                $.ajax({
                    type: 'POST',
                    url: "/widget/measurableresults",
                    data: {
                        text: text,
                    },
                    success: function (msg) {
                        console.log("Success");
                    },
                    error: function (msg) {
                        console.log(msg);
                    }
                });
            });

Here is my route

Route::post('/widget/measurableresults', 'WidgetController@measurableresults');

Here the method in my controller

 public function measurableresults()
    {
        $text = Input::get('text');
        Log::debug( $text );
        return view('results.measurableresults');
    }

The Log::debug prints out the value of $text and the ajax call returns success. However, the view does not change to results.measurableresults. What am I missing?

  • 写回答

1条回答 默认 最新

  • 狐狸.fox 2017-06-28 23:35
    关注

    Try and remove the line Log::debug( $text );, it's probably blocking the return statement to execute

    update

    You seem not to understand how things work in ajax and php communication, the success code you're receiving doesn't mean ajax returned the expected value, if you log the ajax response, you'll get the html text in the view you're returning, it's not that ajax will magically change the view for you.

    Please make more research in regards to this.

    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?