var xmlHttp;

if (window.addEventListener) {
  window.addEventListener('load', init, false);
} else {
  window.attachEvent('onload', init);
}

function init() {
  request("GET", "news4.php", false);
}

function createHttpObject() {
  if (window.XMLHttpRequest) {
    return new XMLHttpRequest();
  } else {
    return new ActiveXObject("Microsoft.XMLHTTP");
  }
}
        
function request(method, url, async) {
  xmlHttp = createHttpObject();
  
  if (xmlHttp != null) {
    xmlHttp.open(method, url, async);
    xmlHttp.onreadystatechange = getData;
    xmlHttp.send();
   } else {
     alert("There was a problem with your request.");
   }
}
        
function getData() {
  if (xmlHttp.readyState == 4) {
    if (xmlHttp.status == 200) {
      var newsItems = document.getElementById('newsItems');
      newsItems.innerHTML = xmlHttp.responseText;
    } else {
     alert("There was a problem with your request.");
    }
  }
}

