Load js files by ajax get error

Load js files by ajax get error

BrownsugarBrownsugar Posts: 2Questions: 1Answers: 0
edited June 2017 in Free community support

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

Answers

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28

    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.

  • rduncecbrduncecb Posts: 125Questions: 2Answers: 28
    edited June 2017 Answer ✓

    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/

  • BrownsugarBrownsugar Posts: 2Questions: 1Answers: 0

    Got it, thanks for answering!

This discussion has been closed.