Ver Mensaje Individual
  #43 (permalink)  
Antiguo 12/01/2010, 18:01
Mr_Raymon
 
Fecha de Ingreso: diciembre-2009
Ubicación: España
Mensajes: 119
Antigüedad: 14 años, 4 meses
Puntos: 2
Respuesta: Combinar Lightbox (jQuery) con datos en XML

Entonces si se pueden hacer dos llamadas tipo $.ajax, ¿seria posible hacer algo parecido a esto?

Código Javascript:
Ver original
  1. // Para TRABAJOS
  2.  
  3.     $.ajax({
  4.    
  5.     type: "POST",
  6.    
  7.     url: "xml/trabajos.xml",
  8.    
  9.     async: false,
  10.    
  11.     dataType: "text",
  12.    
  13.     success: function(data) {
  14.    
  15.     function stringToDoc(s) {
  16.     var xml;
  17.     if (window.ActiveXObject) {
  18.     xml = new ActiveXObject('Microsoft.XMLDOM');
  19.     xml.async = 'false';
  20.     xml.loadXML(s);
  21.     return xml;
  22.     }
  23.     else
  24.     xml = (new DOMParser()).parseFromString(s, 'text/xml');
  25.     return (xml && xml.documentElement && xml.documentElement.tagName
  26.     != 'parsererror') ? xml : null;
  27.     };
  28.     xml = stringToDoc(data);
  29.    
  30.     $(xml).find('web').each(function(){
  31.    
  32.     imagen = $(this).find('imagen').text();
  33.     info = $(this).find('info').text();  
  34.     empresa = $(this).find('empresa').text();
  35.     tecnologia = $(this).find('tecnologia').text();
  36.     miniatura = $(this).find('miniatura').text();
  37.     proyecto = $(this).find('proyecto').text();
  38.    
  39.     li = '<li><a href="'+imagen+'" rel="prettyPhoto[web]" title="'+info+'<br/>'+empresa+'<br/>'+tecnologia+'"><img src="'+miniatura+'" class="imagen_hover" alt="<strong>'+proyecto+'</strong>"/></a></li>';
  40.    
  41.     $(".galeria_web").append(li)
  42.    
  43.     }) // fin de each
  44.    
  45.     },
  46.    
  47.     error: function(avisoError) {
  48.    
  49.     alert("No ha sido posible cargar los datos. Por favor, intentelo mas tarde.");
  50.    
  51.     }
  52.    
  53.     });
  54.  
  55. // Para NOTICIAS
  56.  
  57.     $.ajax({
  58.    
  59.     type: "POST",
  60.    
  61.     url: "xml/noticias.xml",
  62.    
  63.     async: false,
  64.    
  65.     dataType: "text",
  66.    
  67.     success: function(data) {
  68.    
  69.     function stringToDoc(s) {
  70.     var xml;
  71.     if (window.ActiveXObject) {
  72.     xml = new ActiveXObject('Microsoft.XMLDOM');
  73.     xml.async = 'false';
  74.     xml.loadXML(s);
  75.     return xml;
  76.     }
  77.     else
  78.     xml = (new DOMParser()).parseFromString(s, 'text/xml');
  79.     return (xml && xml.documentElement && xml.documentElement.tagName
  80.     != 'parsererror') ? xml : null;
  81.     };
  82.     xml = stringToDoc(data);
  83.    
  84.     $(xml).find('noticia').each(function(){
  85.    
  86.     titulo = $(this).find('titulo').text();
  87.     fecha = $(this).find('fecha').text();  
  88.     info = $(this).find('empresa').text();
  89.    
  90.     not = '<p>'+fecha+'</p><p>'+titulo+'</p><p>'+finfo+'</p>'; 
  91.  
  92.         $(".noticias").append(not)
  93.    
  94.     }) // fin de each
  95.    
  96.     },
  97.    
  98.     error: function(avisoError) {
  99.    
  100.     alert("No ha sido posible cargar los datos. Por favor, intentelo mas tarde.");
  101.    
  102.     }
  103.    
  104.     });

Última edición por Mr_Raymon; 12/03/2010 a las 04:29