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::auth();
Route::get('/home', 'HomeController@index');
Route::get('/videos', 'VideosController@index');
Route::post('/videos/fetch', array('before' => 'ajax_check'), 'AjaxController@postFetch');
});
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 }
});
request.fail(function( 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
web
do exactly? YourpostFetch()
method doesn't declare the$data
variable, is that because you removed the code to simplify it? Also your post route isn't correct. It should be in the following formatRoute::post('videos/fetch', array( 'before' => 'ajax_check', 'uses' => 'AjaxController@postFetch' ));
– Jeemusuphp artisan routes
show the expected routes? – Jeemusu