2016-01-16 23 views
1

我正在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行

+0

的MethodNotAllowed暗示你的帖子路線沒有被拾起。中間件「web」究竟做了什麼?你的'postFetch()'方法沒有聲明'$ data'變量,是因爲你刪除了代碼來簡化它?你的帖子路線也不正確。它應該採用以下格式:Route :: post('videos/fetch',array( ''''''''ajax_check',' ''use'=>'AjaxController @ postFetch' ));' – Jeemusu

+0

$ data是一代是省略的。中間件Web管理會話信息。我相信問題出在route.php上,但我不確定它是什麼,關於POST數據管理方式。 – jonystorm

+0

你有啓用路由緩存嗎? 'php artisan routes'是否顯示預期的路線? – Jeemusu

回答

2

MethodNotAllowed例外暗示你的帖子路線沒有被拾起。你的帖子路線的格式對我來說看起來有點奇怪。它應該是以下格式

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

+0

我試過了但我仍然遇到同樣的錯誤 – jonystorm

0

您是否在存儲文件夾中設置了權限?請使用以下命令檢查你的PHP內部服務器錯誤的更多信息:

tail /var/log/php_errors.log 
+0

您也可以在此處查看此解決方案[鏈接](http://stackoverflow.com/a/32257188​​/1763461) – PhillipMwaniki

相關問題