Skip to content

Instantly share code, notes, and snippets.

@landsman
Created March 19, 2017 22:10
Show Gist options
  • Save landsman/eebb013eb710e20a8fa67c1bf7000c29 to your computer and use it in GitHub Desktop.
Save landsman/eebb013eb710e20a8fa67c1bf7000c29 to your computer and use it in GitHub Desktop.
vanilla javascript loading html content async
function loadBlocks()
{
var crosspromoSites = [
'elle',
'marieclaire',
'apetitonline',
'svetzeny'
];
var parentElement = document.getElementById('crosspromo');
crosspromoSites.forEach(function(magazine, index)
{
var request = new XMLHttpRequest();
request.open('GET', 'http://promo.burdamedia.cz/crosspromo/marianne/' + magazine + '/1', true);
request.onload = function (e) {
if (request.readyState === 4)
{
if (request.status === 200)
{
var wrapper = document.createElement('div')
wrapper.id = 'crosspromo-' + index;
wrapper.innerHTML = request.responseText;
parentElement.appendChild(wrapper);
}
else
{
console.error(request.statusText);
}
}
};
request.send(null);
});
}
loadBlocks();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment