Using Ajax and returning json array in laravel 5

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

    <meta name="csrf-token" content="{{ csrf_token() }}" />
    
  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);
        }
    });
    

Add error callback to your ajax request to find if an error is thrown,

$.ajax({
  type    :"POST",
  url     :"http://localhost/laravel/public/form-data",
  dataType:"json",
  data    :{ data1:data },
  success :function(response) {
    alert("thank u");
  },
  error: function(e) {
    console.log(e.responseText);
  }
});

its better to use console.log() to see detailed information even if the response is a json string. Try the code and let us know if something is logged to the browser console