If you are not using jQuery or another library with built-in ajax methods:
var setHtml = function (element, url) { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function () { if (xhr.readyState == 4 && xhr.status == 200) { element.innerHTML = xhr.responseText; } }; xhr.timeout = 10000; xhr.open('GET', url, true); xhr.send(); };
Then just call the setHtml function as follows:
setHtml(document.getElementById('centerPane'), 'SampleHTML.htm');
source share