Reputation: 3091
I have a html file with function displayJsonWithAjax
and function displayOtherJsonWithAjax
declared in a script-tag.
In another script-tag, I invoke those functions with this code when a select box change:
<script>
import fetchJson from 'some.module'
function displayJsonWithAjax() {
...
}
function displayOtherJsonWithAjax() {
...
}
</script>
<script>
$(document).ready(function () {
$('#selectBox').change(function () {
displayJsonWithAjax();
displayOtherJsonWithAjax();
}).change();
});
</script>
When debugging with a browser, I get the following error:
ReferenceError: displayJsonWithAjax is not defined
If I try to put all the functions in the same script tag, no code is automatically executed when the browser load the page... How do I accomplish to call these two functions?
Upvotes: 0
Views: 59
Reputation: 3507
import fetchJson from 'some.module'
Does that really work? Check you console.
If a script line fails, everything after that line won't be executed, so the script functions won't be declared and won't be usable elsewhere (and that will explain why "If I try to put all the functions in the same script tag, no code is automatically executed when the browser load the page": the script fails at line 1, and nothing else is executed).
Upvotes: 3