SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    A troublesome first foray into Ajax

    I decided to dabble in some Ajax this afternoon and am having some issues with it. Here's the JS:
    Code Javascript:
    function ajax() {
      var req;
      if (window.XMLHttpRequest) req = new XMLHttpRequest();
      else if (window.ActiveXObject) {
        try {req = new ActiveXObject("Msxml2.XMLHTTP")}
        catch (e) {
          try {req = new ActiveXObject("Microsoft.XMLHTTP")}
          catch (e) {}
        }
      }
      req.onreadystatechange = function() {showResponse(req);}
      req.open('GET', 'http://127.0.0.1/test.php?ajax=yes', true);
    }
     
     
    function showResponse(response) {
      if (response.readyState == 4) {
        if (response.status == 200) {
          alert(response.responseText);
        }
      }
    }

    test.php:
    PHP Code:
    <?php
    echo 'hello';
    ?>
    Nothing is received from the server - the response.readyState always seems to be 1. I'm trying this out locally using XAMPP, but I'd be surprised if this is a problem.

    This is pretty much identical to all the examples out there, such as the one on devmo. What am I doing wrong? I'm stumped. Any enlightenment is greatly appreciated!

  2. #2
    SitePoint Wizard stereofrog's Avatar
    Join Date
    Apr 2004
    Location
    germany
    Posts
    4,324
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you forgot to send() the request

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh man, do I feel daft.

    Cheers stereofrog.

  4. #4
    Worship the Krome kromey's Avatar
    Join Date
    Sep 2006
    Location
    Fairbanks, AK
    Posts
    1,621
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Heh, incidentally this was 100&#37; identical to my first foray into AJAX. Except that once I finally figured out that I hadn't sent the request, I then discovered (after much more head-beating) that I also had mistyped the URL!

    So all-in-all, Raffles, you're off to a better start than I!
    PHP questions? RTFM
    MySQL questions? RTFM


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
  •