SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    error on page in an AJAX example

    Code:
    code
    
    <script type=text/javascript>
    function showHint(str)
    {
    if (str.length==0)
    {
    document.getElementById("txtHint").innerHTML=""
    return
    }
    xmlHttp=GetXmlHttpObject()
    if (xmlHttp==null)
    {
    alert ("Browser does not support HTTP Request")
    return
    }
    var url="gethint.asp"
    url=url+"?q="+str
    url=url+"&sid="+Math.random()
    xmlHttp.onreadystatechange=stateChanged
    xmlHttp.open("GET",url,true)
    xmlHttp.send(null)
    }
    function stateChanged()
    {
    if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
    {
    document.getElementById("txtHint").innerHTML=xmlHttp.responseText
    }
    } 
    
    </script>
    
    <form>
    First Name:
    <input type="text" id="txt1"
    onkeyup="showHint(this.value)">
    </form>
    
    <p>Suggestions: <span id="txtHint"></span></p>
    The code is from http://w3schools.com/ajax/ajax_example.asp

    As I enter any character into the input field expecting the character is shown in the txtHint span area, it says "error on page" on the status bars.

    What's wrong with the code? or What's wrong in my expecting?

  2. #2
    Made with a Mac! philm's Avatar
    Join Date
    Sep 2001
    Location
    Portsmouth, UK
    Posts
    735
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you followed it all?

    There's another file 'gethint.asp' or 'gethint.php', whichever language you want to use...

  3. #3
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by philm
    Have you followed it all?

    There's another file 'gethint.asp' or 'gethint.php', whichever language you want to use...
    Thank you.

    But I can't see where is the 'gethint.asp' or 'gethint.php' on that page.

    Where can I fint it, please?

  4. #4
    SitePoint Member bluefooz's Avatar
    Join Date
    Mar 2005
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    joon, what you're missing is on that particular W3Schools Ajax Example, they have this file called gethint.asp (http://w3schools.com/ajax/gethint.asp). You can tell this by looking at the following line in the code:
    Code:
    var url="gethint.asp"
    This file is used to provide name suggestions as you type. For example, if you type: "a", the Ajax engine on that page will query gethint.asp using this URL: http://w3schools.com/ajax/gethint.asp?q=a, and gethint.asp will produce response such as: "Anna, Amanda". If you type "br", the URL would be: http://w3schools.com/ajax/gethint.asp?q=br, and the response: "Brittany".

    What you need is to create a file which is able to provide you with the same functionality as gethint.asp, or to get the suggestion data from an XML file.

    Anyone please correct me if I'm wrong since I'm also new at this. Thanks!


Bookmarks

Posting Permissions

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