Jump to content

Most basic W3School AJAX tutorial not working for me


avylon

Recommended Posts

The very first sample in the W3School AJAX tutorial at http://www.w3schools.com/ajax/default.asp is not working for me.  In this simple example, the time from the server is supposed to appear in the second textbox as I begin to type in the first textbox.  Nothing happens at all, though.  There are two pages in this example: ajaxTest.htm and time.asp. Both are hosted in the same folder.

 

Here is the unaltered code for ajaxTest.htm:

<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>

=============================

Here is the code for time.asp:

<%

response.expires=-1

response.write(time)

%>

=============================

 

If I visit time.asp directly, I get the correct time.  If I visit ajaxTest.htm and begin to type in the name field, nothing happens.  I tried it in FF and IE.  I'm on Windows 2005 Server, so ASP is not an issue, either.  Do I need to make an IIS change for this to work?

 

Thanks for any help.

Patrick

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.