Laravel Ajax POST 500(内部服务器错误)

时间:2017-03-13 03:33:57

标签: ajax laravel-5

我正在尝试使用ajax为我的数据表添加一个新行 这是我添加新行的模式:

<div id="modal-add-team" class="modal fade" aria-hidden="true" role="dialog" novalidate>
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-body">
            <div class="row">
                <button type="button" class="close" data-dismiss="modal">&times;</button>

                <div class="col-sm "><h3 class="text-center m-t-none m-b">Add Team</h3>

                    <p>Add Team</p>

                        <div class="form-group"><label>Team Name</label> <input type="text" placeholder="Enter Name" class="form-control" id="name" name="name" required>   @if ($errors->has('name')) <p class="help-block">{{ $errors->first('name') }}</p> @endif
                        </div>

                        <div class="form-group"><label>Parent Team</label> <input type="text" placeholder="Enter Niche" class="form-control" id="parent-id" name="parent-id"></div>   


                        <button id="addTeam" class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"  style="width: 100%;" onclick="pressOnlyOnce()" ><strong>Add</strong></button>

                    </div>
            </div>

        </div>
    </div>
</div>

这是我的ajax:

  $.ajax({
        type: 'POST',
        url: '{{ url('/ajax/add-team') }}',
        data: {
            '_token': $('input[name=_token]').val(),
            'name': $('input[name=name]').val(),
            'parent_id': $('input[name=parent_id]').val()
        },

        success: function(data) {
            if ((data.errors)){
                $('.error').removeClass('hidden');
                $('.error').text(data.errors.name);
            }
            else {
                $('.error').addClass('hidden');
                window.location.href='{{ url('/teams') }}';
                $('#table').append("<tr class='item" + data.id + "'><td>" + data.id + "</td><td>" + data.name + "</td><td><button class='edit-modal btn btn-info' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-edit'></span> Edit</button> <button class='delete-modal btn btn-danger' data-id='" + data.id + "' data-name='" + data.name + "'><span class='glyphicon glyphicon-trash'></span> Delete</button></td></tr>");
            }
        },

    });
    $('#name').val('');

但它甚至没有到达我的控制器的地步。它只是说错误500 ...我哪里出错?

0 个答案:

没有答案