laravel:如何通过控制器中的ajax检索POST数据

iTe*_*nzo 4 jquery controller laravel

我正在尝试检索$_POST通过jquery ajax func提交的数据,但似乎没有任何传递.这是我的代码:首先是我的表格:

{{  Form::open('', 'POST', array('id'=>'ajax')) }}

    {{ Form::text('_date', '', array('id'=>'datepicker', 'class'=>'app_date')) }}
    {{ Form::submit('Go', array('id'=>'go')) }}

{{  Form::close() }}
Run Code Online (Sandbox Code Playgroud)

和jquery:

$('#ajax').submit(function(e){

    $.ajax({
        url: 'appajax',
        type: 'POST',
        data: $('.app_date').val(),
        dataType: 'json',
        success: function(info){
                     console.log(info);
         }
    });

    e.preventDefault();
});
Run Code Online (Sandbox Code Playgroud)

......最后在控制器中:

public function post_appajax()
    {

        return Response::json(Input::get('_date'));

    }
Run Code Online (Sandbox Code Playgroud)

在控制台中输出是NULL.我错过了什么?我正在使用目前可从laravel.com下载的laravel 3.谢谢.

und*_*ned 8

当您使用POST方法时,您应该传递键/值对而不是字符串,对象,更改:

data: $('.app_date').val(),
Run Code Online (Sandbox Code Playgroud)

至:

data: { _date: $('.app_date').val() },
Run Code Online (Sandbox Code Playgroud)

  • 对不起,但我如何将答案标记为"解决方案"?帮助,想成为一个好公民:) (2认同)