Why JQuery code does not work when i click on button?

  jquery, laravel

What is the problem with my JQuery code when I click on the button it does not work, I searched a lot and tried many ways but my problem not solved. I used this code in other files, on there it works correctly but it not work in this file.

this my table:

<table class="table table-bordered">
                              
       <tbody>
         <?php
          $insideOrders = AppOutsideModel::where('total_id', '=', $order->order_id)->get();
                                ?>
                    @foreach($insideOrders as $index => $inside)
                         <tr>
                            <td>{{ $index + 1 }}</td>
                            <td>{{ $inside->menu->name }}</td>
                            <td>{{ $inside->menu->category->name }}</td>
                            <td>{{ $inside->order_amount }}</td>
                            <td>
                                @if($order->status=='1')
                                   <button id="send_order" class="btn btn-primary btn-xs"
                                     order_id="{{$order->order_id}}">ارسال<i id="send_icon"></i>
                                   </button>
                                     @else
                                      <button class="btn btn-success btn-xs" disabled>ارسال شده</button>

                                     @endif
                                   </td>
                              </tr>
                    @endforeach
                </tbody>                
         </table>

This is my js:-.

$('table tbody').on('click', 'button', function () {
        var order_id = $(this).attr("order_id");

        $.ajax({
            url: '{{route('sendOrders')}}',
            type: 'GET',
            dataType: 'json',
            data: {
                'id': order_id
            },
            success: function (response) {
                if (response) {
                    alert('ارسال شد!');
                    window.location.reload();
                }
                else {
                    alert('ارسال نشد!')
                }

            }, error: function (err) {


            }
        })

    });

Source: Laravel

Leave a Reply