0

in my project I need to call javascript file as asynchronous. Ιf i use asynchronous, means script will send a request to the server, and continue it's execution without waiting for the reply. My problem is if I call JavaScript file as async "Uncaught ReferenceError: initcall is not defined " I face the above error,

<script type="text/javascript" src = "somepath/test.js" async></script>

I call initcall() function in html file and I just put alert() box in that function, If I run html file means I face this type of error, If I remove async call and run means alert is shown , what is the issue in async call?,I need to make my JavaScript file as async call. Anyone suggest me for my problem

Thiyagu
  • 746
  • 3
  • 11
  • 29
  • JS file is loaded asynchronously. You call function before it is loaded and executed, it obviously does not work. If you remove `async`, then browser waits for this JS to load and execute synchronously and it obviously does work if you call `initcall()` after loading `test.js`. – Yeldar Kurmangaliyev Jul 28 '17 at 09:16
  • @Yeldar Kurmangaliyev - obviously I call the function after loading of js then also I face the function undefined error – Thiyagu Jul 28 '17 at 09:24
  • You call the function not after loading of js but after telling browser to start loading JS :) By the time you call your function, you cannot know whether it has executed `test.js` or not. – Yeldar Kurmangaliyev Jul 28 '17 at 09:25
  • OK, Is there any other way is there for my problem ? – Thiyagu Jul 28 '17 at 09:34

0 Answers0