AJAX help

Recommended Videos

hittite

New member
Nov 9, 2009
1,680
0
0
I can't figure out what's wrong. I'm just trying to get the hang of how AJAX works right now, so I found a tutorial. I copy/pasted the code they gave, but it doesn't work. I click the button and nothing happens. I know it's going to be something really simple that I missed, but I just don't know what's wrong. Anyone out there have any suggestions?
 

Blade1130

New member
Sep 25, 2011
175
0
0
hittite said:
I can't figure out what's wrong. I'm just trying to get the hang of how AJAX works right now, so I found a tutorial. I copy/pasted the code they gave, but it doesn't work. I click the button and nothing happens. I know it's going to be something really simple that I missed, but I just don't know what's wrong. Anyone out there have any suggestions?
I've never really worked with AJAX, though I do have plenty of experience with other languages. I can tell you right now, that no one can help you unless you show us some of the code they gave you, or perhaps some steps you took debugging, any ideas you might have about, any concerns you have, perhaps a link to the tutorial you used. Something along those lines to give us an idea about what's going on.
 

hittite

New member
Nov 9, 2009
1,680
0
0
Blade1130 said:
hittite said:
I can't figure out what's wrong. I'm just trying to get the hang of how AJAX works right now, so I found a tutorial. I copy/pasted the code they gave, but it doesn't work. I click the button and nothing happens. I know it's going to be something really simple that I missed, but I just don't know what's wrong. Anyone out there have any suggestions?
I've never really worked with AJAX, though I do have plenty of experience with other languages. I can tell you right now, that no one can help you unless you show us some of the code they gave you, or perhaps some steps you took debugging, any ideas you might have about, any concerns you have, perhaps a link to the tutorial you used. Something along those lines to give us an idea about what's going on.
Oops. Sorry.
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();
}




Start typing a name in the input field below:

First name:

Suggestions:

<%
response.expires=-1
dim a(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"

'get the q parameter from URL
q=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" if no hint were found
'or output the correct values
if hint="" then
response.write("no suggestion")
else
response.write(hint)
end if
%>

It works here
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_suggest
 

Blade1130

New member
Sep 25, 2011
175
0
0
Wait, you mentioned a button earlier.

hittite said:
I click the button and nothing happens.
What button are you talking about? The thing updates itself automatically as you put in data. There shouldn't be a button at all, and I don't see one in your code, unless you are talking about the button at w3schools, in which case, that button should only do something if you changed the code on the left, which I don't see why you would do if you are trying to recreate this program on your machine.

Also, I see a few brackets in your code [] where they shouldn't be. After typing this message I see that get changed to [] when you post, so I'm assuming that's what happened. If not you should probably change [] to at least in your HTML code, as I can't think on an HTML example that uses them.

Where are you getting the AJAX code? I only see the HTML and JavaScript code, unless it's on another page you didn't link to, in which case the connection between the 2 sections is probably where the issue is. Though I'd have to see the original AJAX code to know for sure, and again that's not really my specialty to begin with.

I am unfamiliar with the xmlHTTP object, but after a bit of research it seems to be used to pull data from a server in real time without refreshing the web page. If that is how it works, then this will not operate on simply the client machine. You would need to have a separate server with the data and program on it, to run correctly. At minimum you could download a program that would make your computer a development server as well, though I'm not sure how well this will work. I don't think they would have put this tutorial up if this was the case, but that's how it looks from my end, maybe if I saw the original AJAX code, I might be able to give you a better idea of why this isn't working.

Sorry for the slow response, I've been kind of all over the place tonight.
 

hittite

New member
Nov 9, 2009
1,680
0
0
Blade1130 said:
One of the other examples I was trying had a button. Sorry about the mix up.
The brackets were originally . I don't know why they changed when I posted them.
AJAX isn't a language, just a "new way to use existing standards." Whatever that means.

After doing some more research (how did civilization exist before Google?) I think my problem is that I'm trying to run it off of my own computer rather than a separate server. I need to check my notes.
 

Blade1130

New member
Sep 25, 2011
175
0
0
I was never really entirely sure what AJAX was, just some kind of server-side scripting or something along those lines. It definitely seems to require a server and I don't think this is going to work client-side only. I'd look up some kind of getting starting video on YouTube that explicitly tells you what you need to run it. I remember when I started some PHP work, it took me almost 3 weeks before I found the right utility to create a server on my machine and run the PHP code. ( http://www.easyphp.org/ was it by the way, dunno if you can use it in this situation) See if you can find something that will just get "Hello World" to pop up using AJAX, and if you can get that, then come back to this one and see what you can do.