LARAVEL:在php中使用javascript变量

I would like to get an id from a button. I need this id in my ajax request. This is my button:

 <form>
      <div class="form-group">
         <button class="btn btn-primary" name="deletecar" id="{{$car->id}}">Delete</button>
      </div>
 </form>

I'm getting the id of the button this way:

<script type="text/javascript">var JcarID = this.id;</script>

Finally my Ajax Request.

$('[name="deletecar"]').click(function (e)
        {
            var JcarId = this.id;
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: '{{ action('CarController@delete', [$user->id, $car->id])}}',
                success: function (data)
                {
                  //   alert(data);
                }
            });
        });

Thx for reading!

SOLUTION

Changed some bits in my code. I changed the url of my request.

$('[name="deletecar"]').click(function (e)
        {
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: '/users/{{$user->id}}/deletecar/'+this.id,
                success: function (data)
                {
                  //   alert(data);
                }
            });
        });

Hard to guess what is your requirement yet either if you want to get the button id value

this.attr('id'); or this.prop('id');

Or if you want to set the id value of button

$('[name="deletecar"]').attr('id', yourvalue)

I think you want to use JcarId rather $car->id in ajax request. Here what you can do rather than directly using PHP code in ajax call.

$('[name="deletecar"]').click(function (e)
        {
            var JcarId = this.id;
            e.preventDefault();
            $.ajax({
                type: "POST",
                url: '/CarController/delete',
                data: {'carId':JcarId}
                success: function (data)
                {
                  //   alert(data);
                }
            });
        });