Visualizzazione dei risultati da 1 a 3 su 3

Discussione: lettura xml via jquery

  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    126

    lettura xml via jquery

    Salve a tutti leggo un file xml con jquery
    Il problema è che ci sono piu tag img in uno stesso nodo e quando leggo con
    var imgPath=$(this).find('img').text();
    mi mette tutto in una stringa tipo:
    (photos/image1.jpgphotos/image2.jpgphotos/image3.jpg)
    mentre a me serve avere i paths uno per volta...

    vi posto il file js e di seguito l'xml

    Grazie
    Codice PHP:
        $(function() {
                $.
    ajax({
                    
    type"GET",
                
                    
    url"Guest_images.xml",
                    
    dataType"xml",
                    
    success: function(xml) {
                    $(
    '<ul id="menuF">[/list]').appendTo("#gallery");
                        $(
    xml).find('category').each(function(){
                            var 
    nome = $(this).attr('name'); 
                            if (
    nome=="photoGallery1"){
                                                        
                                                    
                                    var 
    imgPath=$(this).find('img').text();
                                
                                $(
    '[*][url="'+imgPath+'"][img]'+imgPath+'[/img][/url]').appendTo("#menuF");
                                
                            }
                            
                            
                        });
                                            
                    $(
    '#gallery a').lightBox();
            
                    }
                });
        
        }); 
    Codice PHP:
    <?xml version="1.0" encoding="UTF-8"?>
    <gallery>
      
      <category name="photoGallery2">
        <img>/image/image_gallery?img_id=14652</img>
      </category>
      <category name="photoGallery1">
        <img>photos/image1.jpg</img>
        <img>photos/image1.jpg</img>
        <img>photos/image2.jpg</img>
        <img>photos/image3.jpg</img>
        <img>photos/image4.jpg</img>
        <img>photos/image5.jpg</img>
        <img>photos/image6.jpg</img>
        <img>photos/image7.jpg</img>
                                    

      </category>
    </gallery>

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    ti serve un altro each, no?
    codice:
    ...
    if (nome=="photoGallery1"){
      $(this).find('img').each(function(){
         var imgPath=$(this).text();
         $('[*][img]'+imgPath+'[/img]').appendTo("#menuF");
      })
    }

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2008
    Messaggi
    126
    grazie funzionaaaa!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.