+ Reply to Thread
Results 1 to 3 of 3

Thread: ajax help

  1. #1
    mindstorm8191 is offline x10Hosting Member mindstorm8191 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    19

    ajax help

    Hello. I don't know how skilled the developers here are, but I could use some assistance with some ajax I'm working on. Based on the ajax tutorials I have seen, its not all that hard, and I have had no trouble getting it to request the target page. The trouble is trying to read the return data and make use of it.

    Here is a copy of my ajax page:
    Code:
    <html>
      <body>
        <script type="text/javascript">
          function doAjax() {
            var link;
            if(window.XMLHttpRequest) {
              link = new XMLHttpRequest();
            }else if(window.ActiveXObject){
              link = new ActiveXObject("Microsoft.XMLHTTP");
            }else{
              alert("Sorry, your browser doesn't support ajax");
            }
            
            link.onreadystatechange = function() {
              if(link.readyState==4) {
                alert(link.responseText);
              }
            }
            
            link.open("get", "test.php", true);
            link.setRequestHeader('content-type', 'text/xml');
            link.send(null);
          }
        </script>
        
        <form>
          <input type="submit" value="testnow" onclick="doAjax()">
        </form>
      </body>
    </html>
    As you can see, this is still a very basic ajax request example, but I still get no data from the return value. If anyone can help me understand why this isn't working correctly, I would certainly appreciate it.

  2. #2
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: ajax help

    Change the type of the "testnow" button from "submit" to "button". Currently, it submits the (empty) form, reloading the page.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

  3. #3
    mindstorm8191 is offline x10Hosting Member mindstorm8191 is an unknown quantity at this point
    Join Date
    May 2009
    Posts
    19

    Re: ajax help

    Hey, that fixed the problem. Thanks for the help.

+ Reply to Thread

Similar Threads

  1. AJAX games...
    By Sup3rkirby in forum Off Topic
    Replies: 1
    Last Post: 09-11-2008, 06:29 PM
  2. PHP and Ajax (Authentication how to ??)
    By oracle in forum Programming Help
    Replies: 3
    Last Post: 06-16-2008, 09:06 AM
  3. AJAX response xml not working
    By jspcodes in forum Programming Help
    Replies: 3
    Last Post: 06-05-2008, 08:12 AM
  4. AJAX Gaming Server?
    By Sup3rkirby in forum Programming Help
    Replies: 14
    Last Post: 12-26-2007, 04:14 PM
  5. ads included by ajax
    By agustinvinao in forum Free Hosting
    Replies: 1
    Last Post: 05-28-2006, 12:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers