简体   繁体   English

在Laravel 5中发送大量数组数据时RouteCollection.php中的MethodNotAllowedHttpException错误

[英]MethodNotAllowedHttpException in RouteCollection.php error while sending huge amount of array data in Laravel 5

I am sending a huge amount of array data through ajax using Laravel. 我正在使用Laravel通过ajax发送大量数组数据。 But every time it's giving me MethodNotAllowedHttpException in RouteCollection.php error. 但是每次它都会MethodNotAllowedHttpException in RouteCollection.php错误中给我MethodNotAllowedHttpException in RouteCollection.php错误。 Below is the AJAX code 下面是AJAX代码

AJAX Code AJAX代码

function getDataSet(data){
         $.ajax({
            url: base_url+'/get-data-set',
            data:{'data':data},      
            type:"POST",
            success:function(response){
                console.log(response);
            },              
         });        
    }

Route: 路线:

Route::post('get-data-set',function(){ /* Do something*/ exit; });

Error Description 错误说明

    in RouteCollection.php line 207
at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 194
at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 142
at RouteCollection->match(object(Request)) in Router.php line 729
at Router->findRoute(object(Request)) in Router.php line 652
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 141
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in VerifyCsrfToken.php line 43
at VerifyCsrfToken->handle(object(Request), object(Closure)) in VerifyCsrfToken.php line 17
at VerifyCsrfToken->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in ShareErrorsFromSession.php line 55
at ShareErrorsFromSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in StartSession.php line 61
at StartSession->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 36
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in EncryptCookies.php line 40
at EncryptCookies->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request)) in CheckForMaintenanceMode.php line 42
at CheckForMaintenanceMode->handle(object(Request), object(Closure)) in Pipeline.php line 125
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 101
at Pipeline->then(object(Closure)) in Kernel.php line 115
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 84
at Kernel->handle(object(Request)) in index.php line 53

You may use incorrect route post request. 您可能使用了错误的路线发布请求。 To easy maintenance in your route should following 为了便于维护,您应该遵循以下路线

Route::post('/get-data-set',function(){ /* Do something*/ })->name('post.data');

And ajax code should 和ajax代码应该

function getDataSet(data){
     $.ajax({
        url: "{{ route('post.data') }}",
        data:{'data':data},      
        type:"POST",
        success:function(response){
            console.log(response);
        },              
     });        
}

You forgot csrf token on your post request. 您在发布请求中忘记了csrf令牌。

function getDataSet(data){
     $.ajax({
        url: base_url+'/get-data-set',
        data:{
            'data':data,
            "_token": "{{ csrf_token() }}"
        },      
        type:"POST",
        success:function(response){
            console.log(response);
        },              
     });        
}

暂无
暂无

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

相关问题 RouteCollection.php中的MethodNotAllowedHttpException-Laravel - MethodNotAllowedHttpException in RouteCollection.php - laravel RouteCollection.php Laravel中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php Laravel Laravel 5中的RouteCollection.php中的MethodNotAllowedHttpException - MethodNotAllowedHttpException in RouteCollection.php in Laravel 5 Laravel 错误:RouteCollection.php 第 219 行中的 MethodNotAllowedHttpException - Laravel error: MethodNotAllowedHttpException in RouteCollection.php line 219 RouteCollection.php 219行中的MethodNotAllowedHttpException错误laravel: - MethodNotAllowedHttpException in RouteCollection.php line 219 error laravel: RouteCollection.php第218行中的MethodNotAllowedHttpException关于更新数据的laravel 5.2 - MethodNotAllowedHttpException in RouteCollection.php line 218 laravel 5.2 on update data Laravel错误:RouteCollection.php第233行中的MethodNotAllowedHttpException - Laravel Error: MethodNotAllowedHttpException in RouteCollection.php line 233 尝试发布查询表单时,我收到Laravel错误“ RouteCollection.php第x行中的MethodNotAllowedHttpException” - I am receiving the Laravel error “MethodNotAllowedHttpException in RouteCollection.php line x” while trying to POST a query form RouteCollection.php 第 219 行中的 Laravel 5 MethodNotAllowedHttpException - Laravel 5 MethodNotAllowedHttpException in RouteCollection.php line 219 Laravel 5:RouteCollection.php第219行中的MethodNotAllowedHttpException - Laravel 5: MethodNotAllowedHttpException in RouteCollection.php line 219
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM