SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    0 Post(s)
    0 Thread(s)

    Thumbs up 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"
      <title>Using XMLHttpRequest</title>
      <script type="text/javascript" src="1.js"></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() {
        };"GET", file, true);
    function displayResponse(request) {
      if (request.readyState == 4) {
        if (request.status == 200 || request.status == 304) {
        <a href="" onclick="grabFile(this.href); return false;">
    Last edited by ralph.m; Jan 31, 2013 at 20:52. Reason: added code tags

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Melbourne, AU
    448 Post(s)
    8 Thread(s)
    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.
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts