...

View Full Version : Getting AJAX to work



kansurr
07-26-2007, 11:04 PM
I have been trying to get this AJAX tutorial to work and it just doesnt seem to work. I can tell i am missing something super small but if someone could please help me. there are three different files that i am using and here they are. when i load the html in my firefox or ie. When i load it this is what i get when i load it. let me know if anyone has any help for me. thanks so much


<% response.expires=-1dima(30)'Fill up array with names a(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" 'gettheqparameterfromURLq=ucase(request.querystring("q"))'lookup all hints from array if length of q>0 if 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 next end if 'Output"no suggestion"ifnohintwerefound'or output the correct values if hint="" then response.write("no suggestion") else response.write(hint) end if %>
Index.html


<html>
<head>
<script src="clienthint.js"></script>
</head>
<body>

<form>
First Name:
<input type="text" id="txt1"
onkeyup="showHint(this.value)">
</form>

<p>
Suggestions: <span id="txtHint"></span>
</p>

</body>
</html>

clienthint.js


var xmlHttp

function showHint(str)
{
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
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)
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
}
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}

gethint.asp


<%
response.expires=-1dima(30)'Fill up array with names
a(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"

'gettheqparameterfromURLq=ucase(request.querystring("q"))'lookup all hints from array if length of q>0
if 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
next
end if

'Output"no suggestion"ifnohintwerefound'or output the correct values
if hint="" then
response.write("no suggestion")
else
response.write(hint)
end if
%>

A1ien51
07-27-2007, 04:17 AM
Does your server support asp? Are you running this on a server or your localhost?

Eric

kansurr
07-30-2007, 03:54 PM
I am running this on my localhost, is there any way to emulate a server enviroment on my machine?

rafiki
07-30-2007, 04:01 PM
yes download XAMPP :) google it
ahh with asp you may need IIS? :S

kansurr
07-30-2007, 05:09 PM
can you give me a link to a quick tutorial on how to use this program? thanks

I have installed the program and installed the perl addon and i tried to put my website into the asp folder, and ran localhost/asp/index.htm, and the wepage came up and i clicked and added some text and it broke saying object not found. anyways if someone could help me out please let me know. thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum