Bonjour,
Je commence à faire mes premiers pas en ajax et la je rencontre pas mal de soucis (Plutot des trucs que je ne
comprend pas).
J'ai un tableau dans ma page qui contient des données qui doivent être rafraichis de manière transparente par rapport au client
Puisque mon tableau contient plusieus données qui doivent être rafraichit, je dois traiter la reponse sous forme XML.
Dans mon action Struts (eq servlet java) je crer et je rempli ma reponse xml
quand j'affiche sur la sortie standard ma reponse j'ai bien ceci :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 /* Création et remplissage de la reponse xml */ StringBuffer returnXML = null; returnXML = new StringBuffer("\r\n<response>"); returnXML.append("\r\n<spot>"+spot+"</spot>"); returnXML.append("\r\n</response>"); //initialisation de la reponse response.setContentType("text/xml"); response.setHeader("Cache-Control","no-cache"); //envoie la chaine XML (reponse serveur au client ajax) response.getWriter().write(returnXML.toString()); //afficher le contenu de returnXML :
Maintenant, je veux traiter la reponse dans mon js mais je ne vois pas du tout comment faire. Deja, comment passer à mon fichier js la reponse ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3 <response> <spot>4988.0</spot> </response>
et ensuite comment la traiter.
Voici mon fichier :
Merci à tous
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
41
42
43
44
45
46
47
48
49
50
51
52
53 var myLocale; // Ce tableau va servir pour stocker les spots afin de les colorier var underlyingArray = new Array(); var nom=new Array(); var valeur=new Array(); // On enlève le ? param = window.location.search.slice(1,window.location.search.length); // On sépare le paramètres.... // first[0] est de la forme param=valeur first = param.split("&"); for(i=0;i<first.length;i++){ second = first[i].split("="); nom[i] = second[0]; valeur[i] = second[1]; } var underlyingID = valeur[1]; function topflop(locale) { if(locale && locale.length > 0) myLocale = locale; var bindArgs = { url: "topturboday.do?underlyingID="+underlyingID+"&loc=" + myLocale, method: "get", mimetype: "text/xml", load: function(type, data) { refreshData(data); } }; dojo.io.bind(bindArgs); runId = setTimeout("tradingfut()", 5000); } function refreshData(data) { var target = document.getElementById("tradingfut"); target.innerHTML = data; var previousSpot = underlyingArray[0]; var newSpot = document.getElementById("tradingfut").innerHTML; underlyingArray[0] = newSpot; if(previousSpot < newSpot) { dojo.lfx.html.highlight(document.getElementById("tradingfut"), "#00B440", 1500).play(); } else if(previousSpot > newSpot){ dojo.lfx.html.highlight(document.getElementById("tradingfut"), "#DE0000", 1500).play(); } //dojo.lfx.html.highlight(document.getElementById("tradingfut"), "#00B440", 1500).play(); }
Partager