
por que me anda solo en algunos navegadores (leer xml)
Publicado por Tiago (10 intervenciones) el 29/10/2016 05:12:58
hola tengo este codigo en javascript pero me anda solo en firefox y safari en los demas navegadores se pincha cunado llega al xmlhttp.send();
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function listaProductos() {
if (window.XMLHttpRequest) {
//para IE7 o +, firefox, chrome, opera, safari
xmlhttp = new XMLHttpRequest();
}else{
//para IE6 o -
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
//se abre el archivo .xml
xmlhttp.open("GET", "productos.xml", false);
xmlhttp.send();
alert('llega');
//se guarda el contenido del xml en un objeto
xmlDoc = xmlhttp.responseXML;
//se guardan todos los nodos PRODUCTOS
var productos = xmlDoc.getElementsByTagName("producto");
//alert(productos[0].getElementsByTagName('nombre')[0].childNodes[0].nodeValue);
//vacio todo el contenido para cargar el nuevo
document.getElementById('contenido').innerHTML='';
//creo toda la lista de productos
var muestra = '<table style="width:100%;" >';
for (var i = 0; i < productos.length; i++) {
muestra+='<tr>\n\
<td><img src="'+productos[i].getElementsByTagName('foto')[0].childNodes[0].nodeValue+'" style="width:100px;heigth:100px;"/></td>\n\
<td class="celdaPrecio"><span class="precio">$ '+productos[i].getElementsByTagName('precio')[0].childNodes[0].nodeValue+'</span></td>\n\
<td class="nomDesc"><span class="nombre">'+productos[i].getElementsByTagName('nombre')[0].childNodes[0].nodeValue+'</span>\n\
<br><br><span class="descripcion">descripcion: '+productos[i].getElementsByTagName('descripcion')[0].childNodes[0].nodeValue+'</span></td>\n\
<td>cantidad:<br><input type="text" id="prod'+i+'" value="1" style="width: 30px;"></td>\n\
<td><img src="iconoCarrito.ico" onclick="agregarProducto('+i+')" style="cursor:pointer;"/></td>\n\
</tr>';
}
muestra+='</table>';
document.getElementById('contenido').innerHTML=muestra;
}
Valora esta pregunta


0