我正在Laravel 5.2.10項目上工作,我試圖通過ajax獲取一些數據,但是我得到一個500錯誤,而且我找不到我錯過了什麼。內部服務器錯誤在Laravel 5.2.10項目上的Ajax請求
這是我的routes.php文件
Route::group(['middleware' => 'web'], function() {
Route::auth();
Route::get('/home', '[email protected]');
Route::get('/videos', '[email protected]');
Route::post('/videos/fetch', array('before' => 'ajax_check'), '[email protected]');
});
的一部分,在我的 'AjaxController.php' 我有了這個功能
public function postFetch()
{
//Process data and come up with $data
return view('videos')->with('video_data', $data);
}
這是JS Ajax調用
var request = $.ajax({
url: "/videos/fetch",
method: "POST",
data: { url : url }
});
request.fail(function(jqXHR, textStatus) {
alert("Request failed: " + textStatus);
});
RouteCollection.php 219行中的MethodNotAllowedHttpException:RouteCollection.php中的路由集合 - > getRouteForMethods(object(Request),array('POST'))中的RouteCollection.php行206 Route 206 Collection中的RouteCollection-> methodNotAllowed(array第158行
的MethodNotAllowed暗示你的帖子路線沒有被拾起。中間件「web」究竟做了什麼?你的'postFetch()'方法沒有聲明'$ data'變量,是因爲你刪除了代碼來簡化它?你的帖子路線也不正確。它應該採用以下格式:Route :: post('videos/fetch',array( ''''''''ajax_check',' ''use'=>'AjaxController @ postFetch' ));' – Jeemusu
$ data是一代是省略的。中間件Web管理會話信息。我相信問題出在route.php上,但我不確定它是什麼,關於POST數據管理方式。 – jonystorm
你有啓用路由緩存嗎? 'php artisan routes'是否顯示預期的路線? – Jeemusu