Uncaught TypeError: Cannot read property 'defaults' of undefined
Uncaught TypeError: Cannot read property 'defaults' of undefined
nachitox
Posts: 2Questions: 1Answers: 0
Hi,
This is the code with the issue:
$.getScript(config.urlDataTablesJS, function() {
$.extend($.fn.dataTable.defaults, {
// etc
});
// etc
});
where config.urlDataTablesJS = https://static2.sitejabber.com/js/datatables.min.1476819401.js
The file exists and the request is finish before running $.extend
.
I wonder why $.fn.dataTable
is undefined. I even try with a timeout but the same occurs.
Any idea why?
Thanks
This discussion has been closed.
Answers
anyone ?
Found this here: https://api.jquery.com/jquery.getscript/
"Success Callback
The callback is fired once the script has been loaded but not necessarily executed."
Looks like the missing execution of this file is the issue: https://static2.sitejabber.com/js/datatables.min.1476819401.js
Just take a look at this - or you might find something better elsewhere:
https://stackoverflow.com/questions/14565365/jquery-getscript-callback-when-script-is-fully-loaded-and-executed
This seems like the best solution - I would try this one:
"The callback is fired once the script has been loaded but not necessarily executed.
what you need to look for instead is how promises act. In this case as you are looking for a script to load asynchronously you can use either "then" or "done" have a look at this thread which explains the difference nicely: https://stackoverflow.com/questions/5436327/jquery-deferreds-and-promises-then-vs-done
Basically done will be called only when a promise is resolved. in our case when the script was loaded successfully and finished running. So basically in your code it would mean:
should be changed to:
"
My guess is that jQuery is being loaded multiple times. DataTables might be getting attached to the first, and then when jQuery is loaded again it will overwrite the first and take any plug-ins with it (that's just how jQuery works).
Might that be the case here?
Allan