Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Oct 2004
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post

    whats wrong with my first ajax

    hi,
    I have just tested my "first ajax" program but suprisingly it did not work for me..
    I copied and paste both "testAjax.htm" and "time.asp"
    There are two textboxes on the page ...if you write a name in textbox 1 ,the other textbox is supposed to display the current time..but it showed nothing
    What am I missing?
    PHP Code:
    <html><body><script type="text/javascript">function ajaxFunction()
      {  var 
    xmlHttp;
      try
        {    
    // Firefox, Opera 8.0+, Safari    xmlHttp=new XMLHttpRequest();    }
      
    catch (e)
        {    
    // Internet Explorer    try
          
    {      xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");      }
        catch (
    e)
          {      try
            {        
    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");        }
          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.open("GET","time.asp",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>

    -----test.asp--------------------------------
    <%
    response.expires=-1
    response.write(time)
    %> 

  • #2
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    Looks like some of the Javascript comments // are blocking some code:
    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    function ajaxFunction()   { 
      var xmlHttp; 
      try   {    // Firefox, Opera 8.0+, Safari 
            xmlHttp=new XMLHttpRequest();
      }   
       catch (e)  {    // Internet Explorer
                 try   {
                        xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
                 }
         catch (e)   {
                     try  {
                        xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
                     }
             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.open("GET","time.asp",true); 
        xmlHttp.send(null);
    }
    /*]]>*/
    </script>

  • #3
    New Coder
    Join Date
    Oct 2004
    Posts
    37
    Thanks
    0
    Thanked 1 Time in 1 Post
    No ..still there is problem..
    inside the textbox there is this" response.expires=-1"

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Posts
    679
    Thanks
    0
    Thanked 16 Times in 15 Posts
    The ajax is working ok, it returns the data you asp script is giving it.
    Check the asp docs to see how to return the time


  •  

    Posting Permissions

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