ajax help

mindstorm8191

New Member
Messages
24
Reaction score
1
Points
3
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.
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
Change the type of the "testnow" button from "submit" to "button". Currently, it submits the (empty) form, reloading the page.
 
Top