Laravel尝试使用ajax将值发布到控制器但是会出错

I'm sending ajax request to store new unit but it throws following error Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No message

My route:

Route::post('add-unit',['as'=>'add-unit','uses'=>'Dashboard\StoreController@addunit']);

ajax request:

$('#btn').on("click", function (e){
 $.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
      }
 });
 e.preventDefault(); 
 var unitname = $('#unit_name_1').val();
 $.ajax({
     type:'post',
     url: "{{URL::route('add-unit')}}",
     data: {
       'unitname':unitname,                 
     },
     success:function(data){}
  });
});

controller

public function addunit(Request $request){
   dd($request->unit_name);  
}

A few things you could check before digging deeper:

What is the actual url that my Javascript is posting to?
So you need to be sure URL::route('add-unit') returns the correct url. Aside, my personal preference is to make use of the route() helper function.

What are my current routes?
Try running php artisan route:list and check all the available routes in you application. Check if this route is in there and has the correct method.

Do any of my other routes intefere with the desired route?
It can happen that other routes intefere with the desired route. For instance you can have a route like /{anything} that matches earlier than with your route /add-unit.

to check what route generate by your application. you can view page source or inspect element.

to test the controller you can use postman..if your controller work fine and the generated url is the right url. it should work fine.

if any of it got error. you can share the error message here..