XJAX重用XMLHttp对象

So I've got a problem when trying to reuse an XMLHttp request object. I'm trying to incorporate AJAX into a site!

See my code below:

var XMLHttp = createXMLHttpRequestObject();
function createXMLHttpRequestObject() {
  var xmlHTTP;

  //First to deal with Internet Explorer >:(
  if (window.ActiveXObject){
    try {
      xmlHTTP = new ActiveXObject("Microsoft.XMLHTTP");
    } 
    catch (e) {
      xmlHTTP = false;
    }
  } else {
    try {
      xmlHTTP = new XMLHttpRequest();
    }
    catch (e) {
      xmlHTTP = false;
    }
  }

  if (!xmlHTTP)
    alert("Oops! Someone just unplugged the internet!");
  else
    return xmlHTTP;

}// XMLHttpRequest

function getAboutMe() {
  if (XMLHttp.readyState == 0 || XMLHttp.readyState == 4) {
    XMLHttp.open("GET", "http://repairiphonesuk.com/rachael/AJAX/getAboutMe.php", true);
    XMLHttp.onreadystatechange = handleServerResponse('AboutMe');
    XMLHttp.send();
  } else {
    setTimeout(getAboutMe(), 1000);
    alert("no");
  }
}

function getHome() {
  if (XMLHttp.readyState == 0 || XMLHttp.readyState == 4) {
    XMLHttp.open("GET", "http://repairiphonesuk.com/rachael/AJAX/getHome.php", true);
    XMLHttp.onreadystatechange = handleServerResponse('home');
    XMLHttp.send();
  } else {
    setTimeout(getHome(), 1000);
    alert("no");
  }
}


function handleServerResponse(from) {
  if (XMLHttp.readyState == 4 && XMLHttp.status == 200) {
    document.getElementById("displayContent").innerHTML = XMLHttp.responseText;
    if (from === 'home') {
      document.getElementById('displayContent').style.backgroundColor=transparent;
    }
  } else if (XMLHttp.status = 404) {
  }
}

When removing the getHome() function and the parameter to the handle request it works! Am I missing something obvious?

onreadystatechange takes a function assignment, what you're doing is calling a function and assigning the return to onreadystatechange. Correct this by wrapping your code in an anonymous function.

XMLHttp.onreadystatechange = function (){handleServerResponse('home')};

setTimeout takes a function as the first argument, what your doing is calling the function, basically the same thing with onreadystatechange, since getHome isn't taking any arguments just pass the function itself

setTimeout(getHome, 1000);