PDA

View Full Version : querying an asp with XMLHttpRequest


dudeamisgriff
08-17-2008, 02:48 PM
does anybody know why this wouldn't come back with "Ellen" in the element_id div?




<html>
<head>
<title>database test</title>

<script type="text/javascript">

var xmlHttp
var str=28

function showHint() {

xmlHttp=GetXmlHttpObject();
if (xmlHttp==null)
{
alert ("Your browser does not support AJAX!");
return;
}
var url="getName.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("element_id").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;
}


</script>
<body>
<a href="#" onclick="showHint()">click</a><br>

<div id="element_id"></div>


getName.asp



<%
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"


i=(request.querystring("i"))

response.write(a(i))
%>

A1ien51
08-18-2008, 04:58 AM
What does it come back with?

Eric

SSJ
08-18-2008, 08:19 AM
I think you need to define the variables inside the function.

var xmlHttp
var str=28

dudeamisgriff
08-18-2008, 04:57 PM
What does it come back with?

Eric

the entire getName.asp

good name but you need to replace the c with a k ;)

A1ien51
08-19-2008, 04:08 AM
Does your server support asp? If you execute the page on its own [without the Ajax] does it work?

Eric

dudeamisgriff
08-22-2008, 07:27 PM
it does now haha. And I've managed to figure out how to parsec xml and got my asp in gear. Now I just need to figure out how to update asp and xml files by user input without loading the xml, modifying the node value and saving. Say two people are changing their last name in a form, I want to update the xml file directly.