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 2 of 2
  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 "test.php"
    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
    Jul 2007
    Location
    UK
    Posts
    223
    Thanks
    0
    Thanked 14 Times in 14 Posts
    Assuming that some line breaks got mangled when you posted the code (that caused two lines to be commented out) and that your actual code is correct, I can see nothing wrong with the code you posted - except your script references "time.asp" and you've posted "-test.asp-". Is this another posting error?

    I know very little about asp but I think that should work. If in doubt you can reference a plain/static xml file instead of "time.asp", which could help in debugging.

    Also I believe IE7 supports the XMLHttpRequest object so your comment is incorrect.
    Last edited by mcjwb; 08-03-2007 at 01:21 PM.


  •  

    Posting Permissions

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