Laravel ajax请求返回500

时间:2017-08-13 19:27:04

标签: ajax laravel

这是JS代码:

<script type="text/javascript">
    $(document).ready(function(){

        $('#add-more-acadimic').on('click', function(){
            $('#add-new-acadimic').modal();
        });

        $('#SaveAcadimic').on('click', function(){

            var name = $('#acadimic').val();
            $.post("{{ route('postInsertAcadimic')}}",{name: name},function(data){
                    console.log(data);
                });
        });


    });
</script>

这是我的路线档案

Route::post('/manage/course/insert_acadimics', [
    'uses' => 'CourseController@postInsertAcadimic',
    'as'   => 'postInsertAcadimic'
]);

这是控制器功能

public function postInsertAcadimic(Request $request)
{
    if($request->ajax())
    {
        return response(Academic::create($request->all()));
    }
}

我在主刀片中使用csrf令牌元标记以及此代码:

$.ajaxSetup({
headers: {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}});

这是控制台错误:

POST http://localhost:8000/manage/course/insert_acadimics 500 (Internal Server Error) XHR failed loading: POST "http://localhost:8000/manage/course/insert_acadimics".

这是laravel日志错误:

[2017-08-06 19:32:42] local.ERROR: exception 'Symfony\Component\Console\Exception\RuntimeException' with message 'Too many arguments, expected arguments "command" "name".' in C:\xampp\htdocs\SMS\vendor\symfony\console\Input\ArgvInput.php:181

0 个答案:

没有答案