Jump to content

gethint.asp example not working


Recommended Posts

Hello,I have copied and pasted the gethint example, on my home computer, from this webpage:http://www.w3schools.com/asp/asp_ajax_asp.aspThis is my HTML page with the java script:=======================================<html><head><title>Test Page :: ASP Arrays</title><link rel="stylesheet" type="text/css" href="css/aspStyle.css"/><script type="text/javascript">function showHint(str){var xmlhttp;if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; }if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","gethint.asp?q="+str,true);xmlhttp.send();}</script></head><body><h3>Start typing a name in the input field below:</h3><form> First name: <input type="text" id="txt1" onkeyup="showHint(this.value)" size="30" /></form><p>Suggestions: <span id="txtHint"></span></p> <br/><br/><div style="text-align:center;"><a href="index.aspx">home</a></div></body></html>And here is the gethint.asp server page:==================================================<%dim a(30)response.expires=-1'Fill up array with namesa(1)="Anna"a(2)="Brittany"a(3)="Cinderella"a(4)="Diana"a(5)="Eva"a(6)="Fiona"a(7)="Gunda"a(8)="Hege"a(9)="Inga"a(10)="Johanna"a(11)="Kitty"a(12)="Linda"a(13)="Nina"a(14)="Ophelia"a(15)="Petunia"a(16)="Amanda"a(17)="Raquel"a(18)="Cindy"a(19)="Doris"a(20)="Eve"a(21)="Evita"a(22)="Sunniva"a(23)="Tove"a(24)="Unni"a(25)="Violet"a(26)="Liza"a(27)="Elizabeth"a(28)="Ellen"a(29)="Wenche"a(30)="Vicky"'get the q parameter from URLq=ucase(request.querystring("q"))'lookup all hints from array if length of q>0if len(q)>0 then hint="" for i=1 to 30 if q=ucase(mid(a(i),1,len(q))) then if hint="" then hint=a(i) else hint=hint & " , " & a(i) end if end if nextend if'Output "no suggestion" if no hint were found'or output the correct valuesif hint="" then response.write("no suggestion")else response.write(hint)end if%>=========================It won't work. No "hints" appear when typing letters a through z.Thanks for your help.

Link to post
Share on other sites
How are you running the page? Are you checking for Javascript errors? Have you tested the ASP page alone?
The javascript is directly from the "Try it yourself" example link, on the left pane. Typing any letter in the right pane text box works on this site, so, we can assume that the javascript is intact. I am running the page like a "test" page to see if this works. No error messages appear when I try it. The page just sits there unresponsive to inputting.Thanks.
Link to post
Share on other sites
Typing any letter in the right pane text box works on this site, so, we can assume that the javascript is intact.
That's not what I was asking, I was asking if you were checking for Javascript errors. When it's not working, you should be checking for errors. Context matters when Javascript is running. Just because it works when you access the page on the w3schools server through your browser doesn't automatically mean that it's going to work any other way you access it from any other computer or server.
I am running the page like a "test" page to see if this works.
I don't know what that means, how specifically do you access the page? Do you open a browser and type in a URL that starts with HTTP?Also, make sure the ASP page works alone. You should be able to access it directly to get a list of names, e.g.:http://localhost/gethint.asp?q=EAssuming the URL is correct, it should return a list of names starting with E.
Link to post
Share on other sites
That's not what I was asking, I was asking if you were checking for Javascript errors. When it's not working, you should be checking for errors. Context matters when Javascript is running. Just because it works when you access the page on the w3schools server through your browser doesn't automatically mean that it's going to work any other way you access it from any other computer or server.I don't know what that means, how specifically do you access the page? Do you open a browser and type in a URL that starts with HTTP?Also, make sure the ASP page works alone. You should be able to access it directly to get a list of names, e.g.:http://localhost/gethint.asp?q=EAssuming the URL is correct, it should return a list of names starting with E.
I have a website on my machine set up using IIS7 with ASP.NET. From there I set up an index home page with links for various asp.net example pages, also from w3schools tutorial site. I added the gethint AJAX example, recently, to the external links javascript and that's how I set it up for "testing."I just went in and changed the javascript using try/catch error checking like so:<script type="text/javascript">

function showHint(str){
try {var xmlhttp;if (str.length==0) { document.getElementById("txtHint").innerHTML=""; return; }if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } }xmlhttp.open("GET","gethint.asp?q="+str,true);xmlhttp.send(); } catch(err) { txt="There was an error on this page.\n\n"; txt+="Error description: " + err.description + "\n\n"; txt+="Click OK to continue.\n\n"; alert(txt); }

}
</script>Nothing changed with the error checking try code block.I tried accessing my copy of gethint.asp, per your instructions above. All I get is the typical ASP.NET error message page:

Server Error in Application "DEFAULT WEB SITE"

Error Summary:HTTP Error 404.3 - Not FoundThe page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.Thanks for your help.

Edited by Luis
Link to post
Share on other sites
That's not what I was asking, I was asking if you were checking for Javascript errors. When it's not working, you should be checking for errors. Context matters when Javascript is running. Just because it works when you access the page on the w3schools server through your browser doesn't automatically mean that it's going to work any other way you access it from any other computer or server.I don't know what that means, how specifically do you access the page? Do you open a browser and type in a URL that starts with HTTP?Also, make sure the ASP page works alone. You should be able to access it directly to get a list of names, e.g.:http://localhost/gethint.asp?q=EAssuming the URL is correct, it should return a list of names starting with E.
PROBLEM SOLVED ==============================================All I had to do, considering I'm in ASP.NET (IIS7 using .Net framework), was change the file extension (gethint.asp) to "gethint.aspx" and declare "q,i,hint" at the top of page.It's working now.Your help has been much appreciated.
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...