Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

AJAX Code HELP

  • 01-10-2007 06:37PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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, Registered Users 2 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