简体   繁体   English

Laravel中RouteCollection.php第218行的MethodNotAllowedHttpException

[英]MethodNotAllowedHttpException in RouteCollection.php line 218 in Laravel

I want to use post method in Laravel but it's throwing exception: MethodNotAllowedHttpException in RouteCollection.php line 218 我想在Laravel中使用post方法,但它抛出异常:RouteCollection.php第218行中的MethodNotAllowedHttpException

Here is the full error : 这是完整的错误:

in RouteCollection.php line 218
at RouteCollection->methodNotAllowed(array('GET', 'HEAD')) in RouteCollection.php line 205
at RouteCollection->getRouteForMethods(object(Request), array('GET', 'HEAD')) in RouteCollection.php line 158
at RouteCollection->match(object(Request)) in Router.php line 766
at Router->findRoute(object(Request)) in Router.php line 621
at Router->dispatchToRoute(object(Request)) in Router.php line 607
at Router->dispatch(object(Request)) in Kernel.php line 268
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request)) in Pipeline.php line 53
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 46
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 137
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in Pipeline.php line 33
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Pipeline.php line 104
at Pipeline->then(object(Closure)) in Kernel.php line 150
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 117
at Kernel->handle(object(Request)) in index.php line 53
at require_once('E:\Laravel\myproject\public\index.php') in server.php line 21  

here is my form code: 这是我的表单代码:

<div id="education_form">
{{ Form::open(array('method' => 'post','data-parsley-validate')) }}
{{ Form::hidden('user_id', Auth::user()->id, array('id' => 'user_id')) }}


<div class="form-group">
    {{Form::label('school','School')}}<span class="required">*</span>
    {{Form::text('school',null,['class'=>'form-
    control','id'=>'school','placeholder'=>'Enter School Name'])}}
</div>
<div class="form-group">
    {{Form::label('degree','Degree')}}<span class="required">*</span>
    {{Form::text('degree',null,['class'=>'form-
    control','id'=>'degree','placeholder'=>'Enter Degree'])}}
</div>

<div class="form-group">
    {{Form::label('specialization','Specialization')}}
    {{Form::text('specialization',null,['class'=>'form-
    control','id'=>'specialization','placeholder'=>'Enter 
    Specialization'])}}
</div>
{{Form::submit('Save',array('id'=>'saveEducation','class'=>'form-submit btn 
btn-success btn-md pull-right'))}}

{{ Form::close() }}
</div>

I am passing data to ajax using url as below that's why there is no url in form tag. 我使用url将数据传递给ajax,如下所示,这就是为什么表单标签中没有url。

<script>
var urlSave = '{{ route('save') }}';
</script>

here is my route file: 这是我的路线档案:

Route::post('/save', [
'uses' => 'MyController@save',
'as' => 'save'
]); 

Please let me know what mistake I am doing...Thanks! 请让我知道我在做什么错......谢谢!

single quotes ended before the word save and started again after the save it cause 单引号在单词save之前结束,并在保存后再次启动

Uncaught SyntaxError: Unexpected identifier Uncaught SyntaxError:意外的标识符

var urlSave = "{{ route('save') }}";

You should try this: 你应该试试这个:

$.ajax({
    url : "{!! route('save') !!}",
    type: "post",
    data : {data:hierarchy.nestable('serialize')},
    success: function(data) {
        //Proceed to success
    },
    error: function (jqXHR, textStatus, errorThrown) {
        //Check for error
    }
});

OR pass action method in form like : OR传递动作方法,如:

{{ Form::open(array('route' => 'route','method' => 'post','data-parsley-validate')) }}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RouteCollection.php第218行中的Laravel MethodNotAllowedHttpException: - Laravel MethodNotAllowedHttpException in RouteCollection.php line 218: RouteCollection.php 第 218 行中的 Laravel 5.2.36 MethodNotAllowedHttpException: - Laravel 5.2.36 MethodNotAllowedHttpException in RouteCollection.php line 218: Laravel表单提交在RouteCollection.php第218行显示MethodNotAllowedHttpException: - Laravel form submit showing MethodNotAllowedHttpException in RouteCollection.php line 218: RouteCollection.php第218行中的MethodNotAllowedHttpException关于更新数据的laravel 5.2 - MethodNotAllowedHttpException in RouteCollection.php line 218 laravel 5.2 on update data laravel 5.3 RouteCollection.php第218行中的MethodNotAllowedHttpException: - laravel 5.3 MethodNotAllowedHttpException in RouteCollection.php line 218: RouteCollection.php第218行中的Laravel XMLHttpRequest MethodNotAllowedHttpException: - Laravel XMLHttpRequest MethodNotAllowedHttpException in RouteCollection.php line 218: RouteCollection.php行218 Laravel 5.2中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php line 218 Laravel 5.2 routecollection.php第218行中的methodnotallowedhttpexception - methodnotallowedhttpexception in routecollection.php line 218 RouteCollection.php第218:4行中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php line 218:4 RouteCollection.php第218行中的MethodNotAllowedHttpException我该怎么办? - MethodNotAllowedHttpException in RouteCollection.php line 218 what can I do?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM