PDA

View Full Version : AJAX - Error: Not Implemented



Frates
Oct 11th, 2007, 11:29 PM
Hi All,

I am having problems with AJAX. Hopefully someone out there has a solution. I have a classic asp program where I am trying to populate a 2nd drop down list based on the first one. However, when I try this i get an error that merely say "not implemented". Below I've trimmed down the code.


Here is the code in the asp program:
<tr>
<td>Agent:</td>
<td>
<Select name="selAgent" onChange='JavaScript:GetAName (this.value,"selectAgentName");'>
<%for x = 0 to nbrAgent%>
<option value="<%=arrAgent(0,x)%>"><%=arrAgent(1,x)%></option>
<%next%>
</select>
</td>
<td>Name</td>
<td id="selectAgentName"></td>
</tr>


Following is the GetAName javascript:

var xmlHttp
var DropDownContainer
function GetAName(str,containerid){
DropDownContainer=containerid;
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null){
alert ("Your browser does not support AJAX!");
return;
}
var url="GetAgentName.asp";
url=url+"?AN="+str;
url=url+"&sid="+Math.random();
xmlHttp.onreadystatechange=stateChanged();
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
} // end function DupSSN

function stateChanged(containerid){
alert(DropDownContainer + " - " + xmlHttp.readyState);
if (xmlHttp.readyState==4){
//alert(xmlHttp.responseText);
document.getElementById(DropDownContainer).innerHTML=xmlHttp.responseText;
}
} // end functon stateChanged

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;
} // end function GetXmlHttpObject


Following is the GetAgentName.asp

<%
Dim AgentNumber
Dim sqlAN, rsAN, arrAN, x, nbrAN

AgentNumber = trim(request("AN")

sqlAN = "Select AgentNameNbr, AgentName " & _
"From AgentName " & _
"Where AgentNbr = '" & AgentNumber & "' " & _
"Order by AgentName"
Set rsAN = Conn.execute(sqlAN)
arrAN = rsAN.getrows
nbrAN = UBOUND(arrAN,2)

rsAN.close
Set rsAN = Nothing

response.write "<Select name=selAgentName>"
response.write "<option value=-1></option>"
for x = 0 to nbrAN
response.write "<option value=" & arrAN(0,x) & ">" & arrAN(1,x) & "</option>"
next
response.write "</select>"
%>


The alert in the function statechanged will give me the ID of the field and 0 as the value of the readyState. I have verifed that the GetNameAgent.asp does work by running the program in I.E. (ver 7). I know it must be something that I am doing. Any Help would be appreciative.

TIA,
Frates

BarrMan
Oct 12th, 2007, 02:19 AM
xmlHttp.onreadystatechange=stateChanged();
Shouldn't you give a value to the containerid to the function parameter?

A1ien51
Oct 12th, 2007, 04:18 AM
xmlHttp.onreadystatechange=stateChanged();

should be

xmlHttp.onreadystatechange=stateChanged;

when you use () that means to execute the code right here and now. You want to assign the reference to the function to the evet handler.

Since you are using a global variable to hold the xmlHttpRequest Object, you should use a global variable for the containerId.

Also the code should be

open
onreadystatechange
send

It gets around some browser bugs.

Eric

Frates
Oct 12th, 2007, 03:07 PM
BarrMan, thanks for you input. I did have that at one time, but read on a website that that function could not accept parameters. The website didn't say why, but i gave it a try. After i passed the id value to the function GetAName I put it in a global variable.

Eric, I owe you a Big Thank You. It worked !!! Took the () off and rearranged the code as you said. Works Great !!! Thanks !!!

Frates