So I have 3 files:
web.html
java1.js
java2.js
I’m loading java1.js in the html. When this runs it writes into web.html with a list of items.
<script type="text/javascript" src="../java1.js"></script>
Then I have jQuery that executes a function in java2.js. What this is supposed to do is populate the html with a different list of items. This code does work because if I load it instead of java1.js, I get a different list.
<a href="#" id ="web" onclick="javascript: $.getScript('java2.js' , function (){ web() ; } );" />
Where I’m having a tough time is, even though java2.js is executing successfully, it doesn’t refresh the data in the html. That seems to make sense so I added this to java2.js
window.location = window.location
and now it does refresh the html but, it reloads java1.js since it loads when the html loads and I’m back to having the original list.
So finally my question is, what’s the best way to execute java2.js without loading java1.js data back into the html?
Thanks you much!
>Solution :
You can store data in localStorage once the data has been loaded, and then check for that data in localStorage before updating the lists:
Java 1:
if (!localStorage.getItem("dataLoaded")) {
lists = []; // set the initial values
}
Java 2:
lists = []; // set new values
localStorage.setItem("dataLoaded", true);