M
matatunos
Hi!
I have a problem with a function that works fine in IE 7.0 and Opera
9.23, over Windows XP Professional SP2, but it doesn't work on Mozilla
firefox (i try with 2.0.0.7 spanish version) and it must work at least
with IE and Firefox
y have two combo-boxes, depending on the selection on the first one, it
calls a VB6 dll (using ASP) and returns one XML, then put the data into
the second combo-box (<select> <option>)
with IE and Opera it works fine, with Firefox it returns "Unknown"
i have tried an alert(xml.xml) returning responseXML in my ajax
function, and it returns 'undefined', but the 'for' works 4 times :-?
if i use responseText and show alert(xml), it works fine and returns
the xml correctly
if i replace
opcion.text=registros.item(i).childNodes[1].text;
with
opcion.text=registros.item(i).childNodes[1].nodeValue;
it returns 'null'
if i replace with
opcion.text=registros.item(i).childNodes[1].nodeName;
it returns the correct name of the node (nombre)
err = http_request.responseXML.parseError; returns 'undefined'
alert(http_request) returns 'Object'
so i cant use this
alert("Error on line " + err.line + "\n" + err.srcText + "\n" +
err.reason + "\n" + err.errorCode);
below is some code, ajax, javascritp function and xml
any issue?
thankyou!
***************************************************************
ajax.js *******************************************************
function makeHttp_request(url,method,parameters,handler)
{
//method: 'GET' o 'POST'
//parameters: null para GET, y 'var1=val1&...&varn=valn' para POST
//handler: nombre de la función que se encargará de tratar el
resultado
var http_request = false;
//crear el objeto http_request
if(window.XMLHttpRequest)
http_request = new XMLHttpRequest();
else if (window.ActiveXObject)
http_request = new ActiveXObject(Microsoft.XMLHTTP);
if (!http_request)
{
alert('ERROR No es posible crear una instancia
XMLHTTP');
return false;
}
http_request.onreadystatechange = function()
{
if (http_request.readyState==4)
{
if(http_request.status==200)
{
// err = http_request.responseXML.parseError;
// if (err.errorCode != 0)
// alert("Error on line " + err.line + "\n" + err.srcText + "\n"
+ err.reason + "\n" + err.errorCode);
//handler(http_request.responseText);
handler(http_request.responseXML); //código a ejecutar si el
código es correcto
}
else
{
if(http_request.status==404)
{
alert("¡¡¡ERROR!!!. La direccion no existe"); //(2) mostrar
error
}
else
{
alert("¡¡¡ERROR!!!. "+http_request.status); //(3) mostrar error
}
}
}
}
http_request.open(method.toUpperCase(), url, true);
if (method=="POST")
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.send(parameters);
return;
}
***************************************************************
myfunction.js*************************************************
function fincargarcomarca(xml)
{
'purge select
var select=vaciarselect("comarca");
'get elements from xmlDOMDocument
var registros = xml.getElementsByTagName("registro");
'create default option
var opcion=document.createElement('option');
opcion.value="0";
opcion.text="-[Ninguna Comarca Seleccionada]-";
'add to select
try
{
select.add(opcion, null); // standards compliant; doesn't work in
IE
}
catch(ex)
{
select.add(opcion); // IE only
}
'
for(var i=0;i<registros.length;i++)
{
var opcion=document.createElement('option');
opcion.value=registros.item(i).childNodes[0].text;
opcion.text=registros.item(i).childNodes[1].text;
try
{
select.add(opcion, null); // standards compliant; doesn't work in
IE
}
catch(ex)
{
select.add(opcion); // IE only
}
}
}
***************************************************************
mydata.xml*****************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<datos>
<provincias>
<registro>
<codprov>15</codprov>
<nombre>A CORUÑA</nombre>
</registro>
<registro>
<codprov>27</codprov>
<nombre>LUGO</nombre>
</registro>
<registro>
<codprov>32</codprov>
<nombre>OURENSE</nombre>
</registro>
<registro>
<codprov>36</codprov>
<nombre>PONTEVEDRA</nombre>
</registro>
</provincias>
</datos>
I have a problem with a function that works fine in IE 7.0 and Opera
9.23, over Windows XP Professional SP2, but it doesn't work on Mozilla
firefox (i try with 2.0.0.7 spanish version) and it must work at least
with IE and Firefox
y have two combo-boxes, depending on the selection on the first one, it
calls a VB6 dll (using ASP) and returns one XML, then put the data into
the second combo-box (<select> <option>)
with IE and Opera it works fine, with Firefox it returns "Unknown"
i have tried an alert(xml.xml) returning responseXML in my ajax
function, and it returns 'undefined', but the 'for' works 4 times :-?
if i use responseText and show alert(xml), it works fine and returns
the xml correctly
if i replace
opcion.text=registros.item(i).childNodes[1].text;
with
opcion.text=registros.item(i).childNodes[1].nodeValue;
it returns 'null'
if i replace with
opcion.text=registros.item(i).childNodes[1].nodeName;
it returns the correct name of the node (nombre)
err = http_request.responseXML.parseError; returns 'undefined'
alert(http_request) returns 'Object'
so i cant use this
alert("Error on line " + err.line + "\n" + err.srcText + "\n" +
err.reason + "\n" + err.errorCode);
below is some code, ajax, javascritp function and xml
any issue?
thankyou!
***************************************************************
ajax.js *******************************************************
function makeHttp_request(url,method,parameters,handler)
{
//method: 'GET' o 'POST'
//parameters: null para GET, y 'var1=val1&...&varn=valn' para POST
//handler: nombre de la función que se encargará de tratar el
resultado
var http_request = false;
//crear el objeto http_request
if(window.XMLHttpRequest)
http_request = new XMLHttpRequest();
else if (window.ActiveXObject)
http_request = new ActiveXObject(Microsoft.XMLHTTP);
if (!http_request)
{
alert('ERROR No es posible crear una instancia
XMLHTTP');
return false;
}
http_request.onreadystatechange = function()
{
if (http_request.readyState==4)
{
if(http_request.status==200)
{
// err = http_request.responseXML.parseError;
// if (err.errorCode != 0)
// alert("Error on line " + err.line + "\n" + err.srcText + "\n"
+ err.reason + "\n" + err.errorCode);
//handler(http_request.responseText);
handler(http_request.responseXML); //código a ejecutar si el
código es correcto
}
else
{
if(http_request.status==404)
{
alert("¡¡¡ERROR!!!. La direccion no existe"); //(2) mostrar
error
}
else
{
alert("¡¡¡ERROR!!!. "+http_request.status); //(3) mostrar error
}
}
}
}
http_request.open(method.toUpperCase(), url, true);
if (method=="POST")
http_request.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http_request.send(parameters);
return;
}
***************************************************************
myfunction.js*************************************************
function fincargarcomarca(xml)
{
'purge select
var select=vaciarselect("comarca");
'get elements from xmlDOMDocument
var registros = xml.getElementsByTagName("registro");
'create default option
var opcion=document.createElement('option');
opcion.value="0";
opcion.text="-[Ninguna Comarca Seleccionada]-";
'add to select
try
{
select.add(opcion, null); // standards compliant; doesn't work in
IE
}
catch(ex)
{
select.add(opcion); // IE only
}
'
for(var i=0;i<registros.length;i++)
{
var opcion=document.createElement('option');
opcion.value=registros.item(i).childNodes[0].text;
opcion.text=registros.item(i).childNodes[1].text;
try
{
select.add(opcion, null); // standards compliant; doesn't work in
IE
}
catch(ex)
{
select.add(opcion); // IE only
}
}
}
***************************************************************
mydata.xml*****************************************************
<?xml version="1.0" encoding="ISO-8859-1"?>
<datos>
<provincias>
<registro>
<codprov>15</codprov>
<nombre>A CORUÑA</nombre>
</registro>
<registro>
<codprov>27</codprov>
<nombre>LUGO</nombre>
</registro>
<registro>
<codprov>32</codprov>
<nombre>OURENSE</nombre>
</registro>
<registro>
<codprov>36</codprov>
<nombre>PONTEVEDRA</nombre>
</registro>
</provincias>
</datos>