Bonjour

En fonction d'un identifiant, je lis un fichier xml et je récupère un titre.

Je retrouve bien mon titre avec la fonction, seulement je ne parviens à le retourner (Undefined).

La fonction :


Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
 
function returnTitre(file) {
 
 
	$.ajax({
        type: "GET",
        url: "../medias/pages.xml",
        dataType: "xml",
        success: function(xml) {
 
			$(xml).find('page').each(function() {
 
				var ref = $(this).attr("ref") ;
				if ( ref == file ) {
					titre = $(this).attr("titre");
 
					//alert(titre) ;
					return titre ;
				}
 
			} );
 
 
 
        }
    });
 
}

C'est un problème de sync et de async, qu'en pensez-vous ?