PDA

View Full Version : Problems with Explorer on a script ajax that calls an asp script


clematis
04-30-2009, 02:11 PM
Hello everyone,

I have a problem with a script in an integrated ajax asp script

The problem is for Explorer (ver. 6.0) but not with Mozilla.
The problem is as follows:

From the following asp script ...

[SIZE="1"]
<html>
<head>
<script src="selectcustomer.js"></script>
<LINK HREF="../../../styles/mainadm.css" TYPE="text/css" REL="stylesheet">
</head><body><form>
<div id="txtHint" style="margin-left:10px ">Seleziona una voce da modificare:
<select size=1 style="font-family:tahoma; font-size:11px; margin-left:21px;" name="elemento" onchange="showItem(this.value)">
<%
dim RS
set RS = Server.CreateObject("ADODB.RECORDSET")
RS.ActiveConnection=Application("AppDSN")
RS.Open("SELECT id, Nome from Catalogo order by nome")
Response.Write("<option selected></option>")
while not RS.EOF
Response.Write "<option value=" & RS("id") & ">" & RS("nome") & "</option>" & vbcrlf
RS.movenext
wend
RS.close
set RS=nothing
%>
</select>
</div>
</form>
</body>
</html>

</SIZE>


With the Mozilla browser by selecting from a combo box works well, but with explorer I get the following error:

Error: run-time error unknown.

The script stops responding immediately after the education &lt;form...&gt; on the script getitem.asp launched
file selectcustomer.js

Here are two scripts:

SELECTCUSTOMER.JS


<SIZE=1>

var xmlHttp

function showItem(str)
{

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


</SIZE>

and GETITEM.ASP

<size=1>
<html>
<head>
<title>Catalogo</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<LINK HREF="../../../styles/mainadm.css" TYPE="text/css" REL="stylesheet">

</HEAD>

<body BGCOLOR=#E4DBE9 LEFTMARGIN=3 TOPMARGIN=3 MARGINWIDTH=0 MARGINHEIGHT=0>

<%
response.expires=-1
sql="SELECT * FROM catalogo WHERE ID="
sql=sql & "'" & request.querystring("q") & "'"
set conn=Server.CreateObject("ADODB.Connection")
conn.Open(Application("AppDSN"))
set rs = Server.CreateObject("ADODB.recordset")
rs.Open sql, conn

colore=rs("colore")
gruppo=rs("gruppo")
specie=rs("specie")
immagine=rs("immagine")
testo=rs("testo")

RS.close
set RS=nothing

%>
<img src="../../../immagini/postit3.gif" border="0" align="absmiddle" style="margin-left:5px; margin-top:5px ">
<br><br>
<form>
<div style="margin-left:10px; ">Colore:
<select name="colore" style="font-family:tahoma; font-size:11px; margin-left:13px;">
<%
dim RSColore
set RSColore = Server.CreateObject("ADODB.RECORDSET")
RSColore.ActiveConnection=Application("AppDSN")
RSColore.Open("Select * from Colori")
Response.Write("<option selected>"& colore & "</option>")
while not RSColore.EOF
if ucase(colore)<> ucase(RSColore(1)) then
Response.Write "<option value=" & trim(RSColore(0)) & ">" & RSColore(1) & "</option>" & vbcrlf
end if
RSColore.movenext
wend
RSColore.close
set RSColore=nothing
%>
</select>
</div>
<div style="margin-left:10px; ">Gruppo:
<select size=1 style="font-family:tahoma; font-size:11px; margin-left:8px; " name="gruppo">
<%
dim RSGruppo
set RSGruppo = Server.CreateObject("ADODB.RECORDSET")
RSGruppo.ActiveConnection=Application("AppDSN")
RSGruppo.Open("Select * from Gruppo order by gruppo")
Response.Write("<option selected></option>")
while not RSGruppo.EOF
Response.Write "<option value=" & trim(RSGruppo(0)) & ">" & RSGruppo(1) & "</option>" & vbcrlf
RSGruppo.movenext
wend
RSGruppo.close
set RSGruppo=nothing
%>
</select>
</div>
<div style="margin-left:10px ">Specie:
<select size=1 style="font-family:tahoma; font-size:11px; margin-left:11px; " name="specie">
<%
dim RSSpecie
set RSSpecie = Server.CreateObject("ADODB.RECORDSET")
RSSpecie.ActiveConnection=Application("AppDSN")
RSSpecie.Open("Select * from Specie order by specie")
Response.Write("<option selected></option>")
while not RSSpecie.EOF
Response.Write "<option value=" & trim(RSSpecie(0)) & ">" & RSSpecie(1) & "</option>" & vbcrlf
RSSpecie.movenext
wend
RSSpecie.close
set RSSpecie=nothing
%>
</select>
</div>

<div style="margin-left:10px ">Immagine:
<input type="text" maxlength=50 value="/colore/immagini/.jpg" size="50" style="font-family:tahoma; font-size:11px; margin-left:0px " name="immagine">
</div>
<div style="margin-left:10px ">Testo:
<textarea style="font-family:tahoma; font-size:11px; margin-left:17px " name="testo" rows=15 cols=60 ></textarea>
</div>
<br>
<br>

<div style="margin-left:170px ">
<br style="line-height:5px ">
<INPUT type="button" value="aggiungi" name="b1" onclick="Controlla()"> <input type="Reset" Value="annulla" id=Reset1 name=Reset1>
</div>
<br>
</form>
<div style="height:1px; background-image:url(../../../immagini/dot1.jpg); margin-left:10px; margin-right:10px "><img src="../../../immagini/spacer.gif"></div>

</body>
</html>



</Size>


Why this different behavior?
Can you help me?

Thanks in advance

bdl
05-01-2009, 04:02 AM
Well, IE v6.0 sucks. Everyone knows this.

Please use the CODE tags when posting code, and indent for readability. It's near IMPOSSIBLE to tell what your code is doing formatted the way it is.

I will prefix this by saying I don't "do" ASP. Surely there is a good ASP-centric forum to figure out if there are any issues with that portion of your application (i.e. the ASP). Having said that, I can read the code well enough, and I can't figure out why your ASP script 'getitem.asp' seems to be doing everything but sending data back to the calling Ajax request. What's with all the markup in that script? Why isn't it simply returning a single string, a JSON object, or XML?


Some general comments on your JavaScript:


onchange="showItem(this.value)"


Your SELECT onchange handler should be using the selectedIndex of the selected OPTION tag to pull the value down, e.g.

onchange="showItem(this.options[this.selectedIndex].value)"

Either method seems to work fine in Firefox, but IE6 may have trouble with that.

This statement, and possibly others, is missing a semicolon.

var xmlHttp


And you initialize this variable again inside the 'GetXmlHttpObject' here:

function GetXmlHttpObject()
{
var xmlHttp=null;


I would take that statement, remove it from the function and replace the other statement with it, this way you have only one initializer, it's global and it's set to a default (null).


if (xmlHttp==null)

That line should use '===' instead of '=='.