Load js files by ajax get error
Load js files by ajax get error
Brownsugar
Posts: 2Questions: 1Answers: 0
Demo: https://jsfiddle.net/Brownsugar/486rn33j/
I'm trying to make some ajax pages, if the page has table than load the scripts and init DataTables plugin, but I keep get errors while loading js files, both $.getScript and directly insert script tag to page happened.
Any solution of this problem? Thanks!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
At first glance I would say you are running into timing issues. jquery.dataTables.min.js must be loaded before you try and load the plugins; dataTables.fixedHeader and dataTables.bootstrap. I expect the plugins are loading before datatables so they have nothing to work on resulting in your undefined errors.
Try restructuring your code to load the plugins only when datatables has loaded.
Yep, timing/dependency problem.
See this fiddle for fix to only load fixedheader and bootstrap integration plugins once datatables is complete, click the getScript button, it's the only one that reliably works because it handles the dependencies: https://jsfiddle.net/syktqj1c/1/
Got it, thanks for answering!