Help me with Ajax?

I want to get data from a sever.

Ex. I have get data with result is:
<input type=“text” name=“pg” value=“hihihi”></a>
when you run it with IE

But, My code don’t run with firefox, chrome:
Help me ???
Thanks all!


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
  <title>Using XMLHttpRequest</title>
  <script type="text/javascript" src="1.js"></script>
</head>

<script>
function getHTTPObject() {
  var xhr = false;
  if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
  } else if (window.ActiveXObject) {
    try {
      xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        xhr = false;
      }
    }
  }
  return xhr;
}

function grabFile(file) {
  var request = getHTTPObject();
  if (request) {
    request.onreadystatechange = function() {
      displayResponse(request);
    };
    request.open("GET", file, true);
    request.send(null);
  }
}

function displayResponse(request) {
  if (request.readyState == 4) {
    if (request.status == 200 || request.status == 304) {
      alert(request.responseText);
    }
  }
}
</script>


<body>
  <p>
    <a href="http://muangay123.com/3.htm" onclick="grabFile(this.href); return false;">
click
    </a>

  </p>
</body>
</html>

What are you expecting that code to do? It isn’t really set up to do anything with the retrieved data. Normally you’d want to place it on the page once you’ve retrieved it. Anyhow, the code works to get the contents of the file. For me, in Chrome at least, I get an alert of the contents of 3.htm.

Your script is in an odd location, though—wedged between the </head> and <body> tags. Preferably, move it to the bottom of the page, just before the </body> tag … or at least put it in the <head> section.