javascript - JSONP Works on browsing to URL but not on refresh -


on page have 2 javascripts. first script (a.js) appends script head of parent page in order pass jsonp. first script takes jsonp array data , puts array second script use. when go hard url works fine. if f5 doesn't work. if add alert first script right after jsonp done works.

so, guessing when refreshing, reason, happens faster , therefore appending of script doesn't have chance happen , array never receives data.

how can fix this?

main page:

<script src="a.js"></script> <script type="text/javascript"> arrayvalueonmainpage = arrayvalue.firstvalue </script> 

a.js:

//fail safe default arrayvalue = {"firstvalue":["null"]};  function initiate(data){         arrayvalue = data; }  function loadjsonp(url){     var head = document.getelementsbytagname('head')[0];     var script = document.createelement('script');     script.type = 'text/javascript';     script.src = url;     head.appendchild(script); }  loadjsonp('/test.json'); 

test.json:

initiate({"firstvalue":["hello"]}); 

on hard browse url firstvalue passed hello.

on f5 refresh firstvalue passed null.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -