DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1

Thread: Ajax function only works once!

  1. #1
    Join Date
    Jul 2007
    Posts
    8

    Ajax function only works once!

    Hello! I have written this test code:

    Code:
    <html>
    <body>
                              
    <script type="text/javascript">
    
    function ajaxFunction() {
      var xmlHttp;
      try { //Firefox, Opera 8.0+, Safari
        xmlHttp = new XMLHttpRequest();
      }
      catch (e) {
        try {
          xmlHttp = new ActiveXObject("MSXML2.XMLHTTP.3.0");
        }
        catch (e) {
          alert("Your browser does not support AJAX!");
          return false;
        }
      }
    
      xmlHttp.onreadystatechange = function() {
        if(xmlHttp.readyState==4) {
          document.myForm.time.value = xmlHttp.responseText;
          xmlHttp.responseText = "";
        }
      }
      xmlHttp.open("get","time.php",true);
      xmlHttp.send(null);
    }
    
    </script>
    
    <form name="myForm">
      Name: <input type="text" onkeyup="ajaxFunction();" name="username" />
      Time: <input type="text" name="time" />
    </form>
    
    </body>
    </html>
    And in time.php:
    Code:
    <?php
      echo date("H:i:s");
    ?>
    And it works, I'm actually surprised. But what doesn’t surprise me is that the function of getting the time to the textbox only works once; the first time I release a key when the left textbox is marked the current time pops up in the right textbox, but the rest of the times (after clearing the textboxes), the same text as before will pop up again, which is the old time and not the current time! I would really appreciate some help here. Surprise me!
    Last edited by TriKri; 07-06-2007 at 05:01 PM.

Similar Threads

  1. call function for button
    By angela_quests in forum VB Classic
    Replies: 2
    Last Post: 04-13-2007, 04:57 AM
  2. Search System Tray
    By MyPlague in forum .NET
    Replies: 2
    Last Post: 03-20-2006, 06:18 PM
  3. Writing in HKEY_LOCAL_MACHINE...Access is denied
    By Martin in forum VB Classic
    Replies: 22
    Last Post: 12-03-2001, 04:53 AM
  4. I still need to know how the copymemory to an object works
    By Floris De Paepe in forum VB Classic
    Replies: 4
    Last Post: 03-22-2000, 03:32 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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center