Created
March 19, 2017 22:10
-
-
Save landsman/eebb013eb710e20a8fa67c1bf7000c29 to your computer and use it in GitHub Desktop.
vanilla javascript loading html content async
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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