mercredi 1 mars 2017

TokenMismatchException in VerifyCsrfToken.php line 53

i made a page view/maessage.php
http://ift.tt/1yCEpkO">

  <script>
     function getMessage(){
        $.ajax({
           type:'POST',
           url:'/getmsg',
           data:{'_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>

in routes.php

Route::get('/ajax',function(){
  return view('message');
});

Route::post('/getmsg','AjaxController@index');

in AjaxController.php

namespace 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);
   }
}

when i ran http://localhost:8000/ajax http://localhost:8000/getmsg generate below error

Whoops, looks like something went wrong.

1/1 MethodNotAllowedHttpException in RouteCollection.php line 218: in RouteCollection.php line 218 and buch of error.....

but when i saw in consol it show below error TokenMismatchException in VerifyCsrfToken.php line 53: in VerifyCsrfToken.php line 53

i can't understand error .i am fresher in laravel. and i aactually don't know the meaning of '_token': '' in message.php. pls. help to solve this error.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire