Tema: id en ajax
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/03/2013, 03:48
hextrem
 
Fecha de Ingreso: febrero-2013
Mensajes: 21
Antigüedad: 11 años, 2 meses
Puntos: 0
Exclamación id en ajax

Buenas necesito ayuda urgente por que no doy con la solucion ni en google ni foros ni nada. Tengo este codigo funciona ok pero solo me recoge el primer valor ya k es autogenerado tengo k concatenar i creo pero no se como ni como luego recoger el valor este es el codigo
Código Javascript:
Ver original
  1. var obj;
  2.            var objs;
  3.             function seleccion(){
  4.                 if(window.XMLHttpRequest){
  5.                     obj=new XMLHttpRequest();
  6.                 }
  7.                 else if(window.AxtiveXObject){
  8.                     obj=new AxtiveXObject("Microsoft.XMLHttp");
  9.                 }
  10.                 else{alert("No dispone de ajax");
  11.                         return;
  12.             }
  13.                
  14.                 var seci = document.getElementById("secion");
  15.                 var secion = seci.options[seci.selectedIndex].value;
  16.                
  17.                 obj.open("GET","lista?secion="+secion,true);
  18.                 obj.onreadystatechange=retorno;
  19.                 obj.send(null);
  20.                
  21.             }
  22.             function retorno(){
  23.              
  24.                     if(obj.readyState==4){
  25.                     if(obj.status==200){
  26.                                      
  27.                     var raiz= obj.responseText;
  28.                     var p = eval("("+raiz+")")
  29.                                          
  30.                     var tabla = "<table border = '1'>";
  31.                     tabla +="<tr>";
  32.                     tabla +="<th>Comprar</th>";
  33.                     tabla +="<th>Producto</th>";
  34.                     tabla +="<th>Precio</th>";
  35.                     tabla += "<th>Descripcion</th>";
  36.                     tabla +="</tr>";
  37.                     for(var i = 0;i<p.length;i++){
  38.                         var ob = p[i];
  39.                     tabla += "<tr>";
  40.                     tabla += "<td>";
  41.                     tabla += "<input type='button' name='Comprar' value='Comprar' onclick='comprar(this)' >";
  42.                     tabla += "</td>";
  43.                     tabla += "<td id=com>";
  44.                     tabla += ob.producto+"</td>";
  45.                     tabla += "<td>"+ob.precio+"</td>";
  46.                     tabla += "<td>"+ob.descripcion+"</td>";
  47.                     tabla += "</tr>";
  48.                    
  49.                 }
  50.                
  51.                     tabla += "</table>"
  52.                     document.getElementById("dato").innerHTML=tabla;
  53.                    
  54.                                  }
  55.                
  56.                     }}
  57.            function comprar(){
  58.                          
  59.                 var pro = document.getElementById("com").innerHTML;
  60.                
  61.                 if(window.XMLHttpRequest){
  62.                     or=new XMLHttpRequest();
  63.                 }
  64.                 else if(window.AxtiveXObject){
  65.                     or=new AxtiveXObject("Microsoft.XMLHttp");
  66.                 }
  67.                 else{alert("No dispone de ajax");
  68.                         return;
  69.             }
  70.            
  71.                or.open("GET","carro?pro="+pro,true);
  72.                or.onreadystatechange=lis;
  73.                or.send(null);
  74.                
  75.            }
  76.            
  77.            function lis(){
  78.              
  79.                     if(or.readyState==4){
  80.                     if(or.status==200){
  81.                                      
  82.                     var list= or.responseText;
  83.                     var l = eval("("+list+")")
  84.                                          
  85.                     var tabla = "<table border = '6'>";
  86.                     tabla +="<tr>";
  87.                     tabla +="<th>Eliminar</th>";
  88.                     tabla +="<th>Producto</th>";
  89.                     tabla +="<th>Precio</th>";
  90.                     tabla += "<th>Descripcion</th>";
  91.                     tabla +="</tr>";
  92.                     for(var i = 0;i<l.length;i++){
  93.                         var li = l[i];
  94.                     tabla += "<tr>";
  95.                     tabla += "<td>";
  96.                     tabla += "<input type='button' name='Eliminar' value='Eliminar' onclick='eliminar()' >";
  97.                     tabla += "</td>";
  98.                     tabla += "<td id=el>";
  99.                     tabla += li.producto+"</td>";
  100.                     tabla += "<td>"+li.precio+"</td>";
  101.                     tabla += "<td>"+li.descripcion+"</td>";
  102.                     tabla += "</tr>";
  103.                    
  104.                 }
  105.                
  106.                     tabla += "</table>"
  107.                     document.getElementById("te").innerHTML=tabla;
  108.                  
  109.                 }
  110.                     }}
  111.            function eliminar(){
  112.                var eli = document.getElementById("el").innerHTML;
  113.                    if(window.XMLHttpRequest){
  114.                     or=new XMLHttpRequest();
  115.                 }
  116.                 else if(window.AxtiveXObject){
  117.                     or=new AxtiveXObject("Microsoft.XMLHttp");
  118.                 }
  119.                 else{alert("No dispone de ajax");
  120.                         return;
  121.             }
  122.            
  123.                or.open("GET","elimina?eli="+eli,true);
  124.                or.onreadystatechange=lis;
  125.                or.send(null);
  126.                
  127.                
  128.              }
Espero su ayuda