Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

AJAX Code HELP

Options
  • 01-10-2007 6:37pm
    #1
    Registered Users Posts: 269 ✭✭


    I have written the following but i am a getting an error message can anyone help

    //testAjax.htm

    <html>
    <head><title>First Ajax</title>
    </head>
    <body>

    <script type="text/javascript">
    function ajaxFunction()
    {
    var xmlHttp:
    try
    {
    //Firefox, Opera 8.0 +
    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.responceText;
    }
    }
    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>


    //time.asp

    <html>
    <head>
    <title>McDonalds</title>
    </head>
    <body>
    <%
    responce.expires=-1
    responce.write(time)
    %>
    </body>
    </html>


Comments

  • Registered Users Posts: 378 ✭✭sicruise


    You have spelling mistakes/colons instead of semi-colons... just clerical errors...

    This works...
    <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","ajax2.html",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>
    


  • Registered Users Posts: 269 ✭✭cyberwit


    Thanks for the help i noticed the mistakes after posing to boards. When i runb the program form the IIS on my computer it does not give me the time only Undefined


  • Users Awaiting Email Confirmation Posts: 351 ✭✭ron_darrell


    1. Everywhere you have responce please replace it with response. Responce is not a word in ASP.

    2. Don't use document.myForm.time.value=xmlHttp.responceText; instead use
    document.getElementByName('time').value = xmlHttp.responseText

    Give that a try and come back to me

    -RD


  • Registered Users Posts: 378 ✭✭sicruise


    Stop being pedantic... he already fixed his spelling mistakes and he's got the element value changing.

    Instead of the asp page that you have just send something like one character instead. One step at a time.

    So your time.asp will just contain this...
    A
    


Advertisement