I have a Javascript function that looks like this ...
function loadInventory() {
var json = [<?php echo $_SESSION['inventory']; ?>];
for(var i = 0; i < json.length; i++) {
var obj = json[i];
for(var key in obj.rgDescriptions) {
document.getElementById('userInventory').innerHTML += '<div class="col-sm-4"><div style="background-color: #2e2e2e;">'+obj.rgDescriptions[key].market_hash_name+'</div></div>';
document.getElementById('loader').classList.remove('loader');
}
}
}
Obviously, it will take a couple of seconds for this function to be completed, which isn't a problem.
However, I want to load the page fully before running that function as the page has a loading animation which is removed in loadInventory() once the HTML has been added.
I've tried doing this ...
$(document).ready(function() {
$(window).load(function() {
loadInventory();
});
});
But it doesn't seem to work very well. The function runs before the page is loaded fully so you can't see the loading animation.
CONCLUSION:
I want to load the page fully. Once that is done, then I want to run loadInventory() which will add more HTML to the page.
Sorry for the mess, it's very difficult to explain really!
var json = [<?php echo $_SESSION['inventory']; ?>];unexpected tokenerror in my console. How does that even work?