AJAX post not sending data to laravel controller

Solution:1

HTML Form

Somewhere in the form add the CSRF Token like this

<meta name="csrf-token" content="{{ csrf_token() }}">

Route

Add a post route

Route::post('/path/to/ajax-form-process', 'FormController@processor');

Form process method

class FormController extends Controller{

  public function processor(Request $request){
    $input = $request->all();

    //Do other processes

    return '200'; //Use any string that is appropriate
  }

}

jQuery Ajax

In your JS/jQuery script add the following

$.ajax({
  type: "POST",
  url: 'path/to/ajax-form-process',
  data: {
    data1: 'data1',
    data2: 'data2',
    data3: 'data3'
  },
  success: function(html){
    console.log(html);
  }
});

Solution:2

i hope this will help you.

set meta-tag like follows

<meta name="csrf-token" content="{{ csrf_token() }}">

set route

Route::get('/your/url/goes/here',
        [
        'uses' => 'TestController@testFunction'
        ]);

set controller function

on top use Input;

public function iddtest()
{
print_r(Input::all());
}

request like follows

$.ajax({
    data: {data1:'data1',data2:'data2'},
    url: '/your/url/goes/here',
    type: 'POST',
    beforeSend: function (request) {
        return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
    },
    success: function(response){
        console.log(response);
    }
})