简体   繁体   中英

Uncaught ReferenceError: jQuery is not defined Laravel

guys. I wanna use Datatables on my view, and I have followed some instructor from the documentation. But, the datatables won't appear and the console just said "datatables.min.js:17 Uncaught ReferenceError: jQuery is not defined".

console screenshot

here are my codes.

head:

    <link rel="stylesheet" type="text/css" href="{{ asset(' css/datatables.min.css')}}">
<script type="text/javascript" charset="utf8" src="{{ asset('js/datatables.min.js')}}"></script>
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>

View:

<table class="table table-hover" id="table">
      <thead>
        <tr text-align="center">
          <td scope="col" text-align="center">Pesawat</td>
          <td scope="col" text-align="center">Pergi</td>
          <td scope="col" text-align="center">Tiba</td>
          <td scope="col" text-align="center">Waktu</td>
          <td scope="col" text-align="center">Durasi</td>
          <td scope="col" text-align="center">Harga</td>
        </tr>
      </thead>
      @if($flight)
      @foreach ($flight as $listflight)
      <tbody style="text-align: justify;">
        <tr>
          <td><img src={{$listflight['image']}}>{{$listflight['airlines_name']}}<br>Flight ID - ({{$listflight['flight_id']}}) </td>
          <td style="font-size: 15px; padding-top: 50px;">{{$listflight['departure_city_name']}} -{{$listflight['departure_airport_name']}}</td>
          <td style="font-size: 15px; padding-top: 50px;">{{$listflight['arrival_city_name']}} - {{$listflight['arrival_airport_name']}}</td>
          <td style="font-size: 15px; padding-top: 50px;">{{$listflight['departure_flight_date_str']}}</td>
          <td style="font-size: 15px; padding-top: 50px;">{{$listflight['duration']}}
          <br> {{$listflight['full_via']}}</td>
          <td style="font-size: 15px; padding-top: 40px; color: #ea7a08;">IDR. {{$listflight['price_value']}} &nbsp;<a href="#" class="btn btn-outline-secondary mt-3" style=""><i class="icon fa fa-receipt"></i>Order Ticket</a>
          </td>
        </tr>
      </tbody>
      @endforeach
    </table>    

datatables:

@push('script')
<script type="text/javascript">
        $(document).ready(function() {
             $('#table').DataTable();
        });
    </script>
@endpush

The order in which you put your script tags in the DOM matters. Datatables depends on jQuery, so jQuery has to be loaded first.

<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" charset="utf8" src="{{ asset('js/datatables.min.js')}}"></script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM