Hello,

dans jQuery, comment est-ce que je peux écrire une méthode qui retourne le contenu d'un fichier XML dans une variable :

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
30
31
32
33
34
35
36
37
38
39
40
//méthode appelante
appelLoadXml = function()
{
	var test_1 = loadXml_1();
 
	//ou
 
	var test_2 = loadXml_2();
}
 
//méthode appelées
loadXml_1 = function()
{
	$.ajax({
		type: "GET",
		url: "path",
		dataType: "xml",
		success: function(xml)
		{
			//ne fontionne pas, on est dans function(xml)
			//et on appelle loadXml_1()
			return xml;
		} //success
	}); //$.ajax
 
	//ne fonctionne pas, loadXml_1() ne connaît pas xml de function(xml)
	return xml;
}
 
//fonctionne seulement si test est un objet html (<div>, <td>, etc...)
loadXml_2 = function()
{
	var test;
 
	$(test).load("path");
	//ou
	test = $().load("path");
 
	return test;
}