Back to the time I was using Node.js, I used to use fs.readFileSync(filename) to call my external functions, where filename is the name of the file to load.
It might be weird but now that I am using jQuery, I'm kind of lost...
Currently I am gathering up 3 different files (one is .html, the two others are .js), and here is how they look :
Here is test.html
<body>
<button id="submitting_button">Valider</button>
<!--//////////////////////-->
<!-- Loads jQuery library -->
<script src="jQuery/jquery.js"></script>
<!-- Loads my jQuery script -->
<script src="jQuery/process.js"></script>
</body>
Here is process.js
$(document).ready(function(){
$('#submitting_button').click(function(){
$.getScript("./functions/my_function.js");
document.write(calculation());
});
});
And finally, here is my_function.js
console.log("NOTE : my_function.js has been reached");
function calculation(){
var result = 3+4;
return result;
}
So when I click on the « Valider » button, nothing happens, except the fact that Chrome console displays an error, noticing me that calculation is not defined... I am guessing that is because using $.getScript() is not a good thing, but I don't know any other function to load/read an external function.
$.getScript("./functions/my_function.js", function(){ document.write(calculation());});