Using Ajax and returning json array in laravel 5

后端 未结 6 586
粉色の甜心
粉色の甜心 2021-01-02 05:27

\"enterI am new to \"AJAX\" and I have been trying to send a request \"ONSELECT\" using \"AJAX

6条回答
  •  感情败类
    2021-01-02 05:58

    Laravel 5 uses csrf token validation for security reasons....try this...

    1. In routes.php

      route post('form-data', 'FormController@postform');
      
    2. In master layout file

      
      
    3. var CSRF_TOKEN = $('meta[name="csrf-token"]').attr('content');
      $.ajax({
          url: '/form-data/',
          type: 'POST',
          data: {_token: CSRF_TOKEN},
          dataType: 'JSON',
          success: function (data) {
              console.log(data);
          }
      });
      

提交回复
热议问题