//Das XMLHttpRequest Objekt
var xmlHttp = false;

//Instanz erstellen
//Beim IE handelt es sich um ein ActiveX Objekt, in den
//anderen Browsern ist es bereits einkompiliert.

//Wir versuchen unser Glück und nehmen an, der User
//surft mit einem M$ Internet-Explorer:

try {
    xmlHttp  = new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
    try {
        xmlHttp  = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
        xmlHttp  = false;
    }
}

//War wohl nix, deshalb nun die Methode für Mozilla und Co.
if (!xmlHttp  && typeof XMLHttpRequest != 'undefined') {
    xmlHttp = new XMLHttpRequest();
}

function generate(){
  if (xmlHttp) {
    xmlHttp.open('POST', 'createFile.php',true);
    xmlHttp.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    xmlHttp.send(null);

    xmlHttp.onreadystatechange = function(){
      if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
        if(xmlHttp.responseText == ''){
          window.location.href = 'downloadFile.php';
        }
      }
    }
  }
}

