I have seen several people ask parts of this question and tried the various solutions but nothing seems to work. I'm not sure if it's the combination or something else in my project that is causing it to not work.
In my project I have various pages that display similar DataTables. I'm wanting to put the initialisation of these tables in one file to save duplication. But I would like to pass in parameters to account for the minor differences between e.g. column headers. Just to complicate it the initialisation is unsurprisingly done on document.ready.
Things I have tried:
Pass vars to JavaScript via the SRC attribute
http://feather.elektrum.org/book/src.html
In the code example below I never hit the second alert. What I want if for it to hit the second and third alerts and for the contents of test_var to be correct:
(cs)html file
<script>
$(document).ready(function () {
var test_var = "Hopefully this has worked";
alert("Pre TestScript");
$.getScript("TestScript.js"); // Tried different paths to the file here as well
});
</script>
TestScript.js
alert("In the TestScript");
alert("Test variable is: " + test_var);
Perhaps I'm going about it all wrong and there is a different/simpler way to achieve the passing of parameters to a script (file) during document.ready