我犯了一個頁面視圖/ maessage.php
https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js「> TokenMismatchException在VerifyCsrfToken.php線53
<script>
function getMessage(){
$.ajax({
type:'POST',
url:'/getmsg',
data:{'_token': '{{ csrf_token() }}'},
success:function(data){
$("#msg").html(data.msg);
}
});
}
</script>
<body>
<div id = 'msg'>This message will be replaced using Ajax.
Click the button to replace the message.</div>
<?php
echo Form::button('Replace Message',['onClick'=>'getMessage()']);
?>
</body>
在routes.php文件
Route::get('/ajax',function(){
return view('message');
});
路線::交
( '/的getMsg', 'AjaxController @索引');在
AjaxController.phpnamespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
class AjaxController extends Controller
{
public function index(){
$msg = "This is a simple message.";
return response()->json(array('msg'=> $msg), 200);
}
}
,當我跑http://localhost:8000/ajax http://localhost:8000/getmsg產生以下錯誤
哎呦,看起來像出事了。
1/1 MethodNotAllowedHttpException在RouteCollection.php行218:在 RouteCollection.php線218和錯誤的布赫.....
,但是當我在CONSOL看到它顯示下面的錯誤
TokenMismatchException在VerifyCsrfToken.php線53:在 VerifyCsrfToken.php線53
我不明白錯誤。我在laravel更新鮮。而我實際上不知道'_token'的含義:'{{ csrf_token() }}'
在message.php中。請。有助於解決這個錯誤。
雅,我讀了那頁,但我無法得到更多的東西。 –