2017-05-27 69 views
-1

我用螢火蟲犯了錯誤:「500(內部服務器錯誤)」。Laravel 5.0 ajax不起作用

我開始使用Ajax,我想明白一個簡單的事情:

$("#boutonRecherche").click(function() { 
$.ajax({ 
url : "/recherche", //I have tried rechercheController.php and ... 
        //...Http/Controllers/Phases/RechercheController.php 
type : "POST", 
data : '&controle=1',//after comments I found this lines triggers error in 
        //...firebug 
dataType : "html" 
}); 
}); 
  1. 什麼是鏈接的最佳途徑?

  2. 如何解決 「500(內部服務器錯誤)」

查看代碼:

{!! Form::open(['url'=>'recherche']) !!} 
{!! Form::submit('solaire',['class'=>'btn btn-primary', 'name'=>'recherche', 
'id'=>'boutonRecherche']) !!} 
{!! Form::close() !!} 

我的路徑:

  1. 我的控制器HTTP /控制器/階段/RechercheController.php

  2. 我查看公共/資源/視圖/相位/ recherche.blade.php

  3. 我的JS丹斯公共/的script.js

在此先感謝;)

+0

錯誤500通常在代碼中的錯誤造成的,請檢查一下,如果你還沒有做出一個錯字。下一個問題可能與請求類型有關。此路由是否允許POST請求? –

+0

是的,這是一個post請求,我的路線看起來像 Route :: post(「/ recherche」,「Phases \ RechercheController @ update」);我檢查了我的錯字。 – Doug21

回答

0

POST請求需要CSRF token
當您發送表單時,請在AJAX字段{_token: csrfToken}中將對象添加到data

csrfToken您可以從表單或從<head>解析您在哪裏創建<meta name="csrf_token" content="{{csrf_token()}}">字段。

如果你想發送GET PARAM,將其附加到URL,所以url : "/recherche?controle=1"