SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Threaded View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    61
    Mentioned
    0 Post(s)
    Tagged
    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!

    Code:
    <!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>
    Last edited by ralph.m; Jan 31, 2013 at 20:52. Reason: added code tags


Tags for this Thread

Bookmarks

Posting Permissions

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