Reputation: 139
I wanted to use DataTables(jquery plugin) in my Laravel project.
So, I put required js and css file links (using cdn) in my blade template, except jquery. Because I know jquery is already there ( linked in my blade template via 'js/app.js') as I'm using Laravel UI package. additionally, running $().jquery
in my browser console shows I've jquery 3.5.1.. aslo bootstrap 4.* is using that.
But I'm getting this - "uncaught referenceError....", behaving like I don't have jQuery.(jQuery scripts are also not working) please see attached image
So, I added jQuery cdn link and got "jQuery deffered exception"
Well, then I removed "js/app.js" from my blade layout. Now DataTables works,jQuery scripts also work, but bootStrap stops working.
How Can I solve this?!!
Upvotes: 1
Views: 1323
Reputation: 139
I found an unusual solution.
If we load app.js in 'deferred' manner, which is default, the problem arises.
<script src="app.js" defer></script>
And just removing defer
attribute solves the problem.
<script src="app.js"></script>
Reason:
DataTable loads when the page loads. But with defer
attribute jQuery loads after the page is loaded. So datatable throws the error that, it couldn't find jQuery.
Upvotes: 2
Reputation: 1302
Use this cdn:
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/v/bs4/dt-1.10.23/datatables.min.css"/>
<script type="text/javascript" src="https://cdn.datatables.net/v/bs4/dt-1.10.23/datatables.min.js"></script>
These are for bootstrap datatable.
Read More about Bootstrap Datatable
Upvotes: 0