Internal Server Error Ajax Request On Laravel 5.2.10 Project

- 1 answer

I'm working on a Laravel 5.2.10 project, I was trying to fetch some data via ajax but I'm getting an 500 error, and I can't find what I'm missing out.

This is part of my routes.php

Route::group(['middleware' => 'web'], function () {
    Route::get('/home', '[email protected]');
    Route::get('/videos', '[email protected]');
    Route::post('/videos/fetch', array('before' => 'ajax_check'), '[email protected]');

On my 'AjaxController.php' I've got this function

public function postFetch()
    //Process data and come up with $data
    return view('videos')->with('video_data', $data);

And this is the JS ajax call

var request = $.ajax({
    url: "/videos/fetch",
    method: "POST",
    data: { url : url }
}); jqXHR, textStatus ) {
    alert( "Request failed: " + textStatus );

MethodNotAllowedHttpException in RouteCollection.php line 219: in RouteCollection.php line 219 at RouteCollection->methodNotAllowed(array('POST')) in RouteCollection.php line 206 at RouteCollection->getRouteForMethods(object(Request), array('POST')) in RouteCollection.php line 158



The MethodNotAllowed exception hints that your post route isn't being picked up. The format of your post route looks a little odd to me. It should be in the following format

Route::post('videos/fetch', array( 'before' => 'ajax_check', 'uses' => '[email protected]' ));