bonjour, je voudrais récupérer les enregistrements d'une table de la BD dans datagrid en utilisant httpservices . ce programme m'affiche seulement le message d'alerte.
voila les fichiers:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13 <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="Composant()"> <mx:Script source="httpService.as"> </mx:Script> <mx:DataGrid id="listecomposants" x="280" y="100" width="400" height="250" rowCount="10"> <mx:columns> <mx:DataGridColumn headerText="Nom Composant" dataField="nomcomposant"/> <mx:DataGridColumn headerText="N° Composant" dataField="idcomposant"/> <mx:DataGridColumn headerText="Prix" dataField="prixcomposant"/> </mx:columns> </mx:DataGrid> </mx:Application>
le fichier httpService.as
le fichier listes.php
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 import mx.controls.Alert; import mx.rpc.events.FaultEvent; import mx.rpc.events.ResultEvent; import mx.rpc.http.HTTPService; public function Composant():void{ var serviceHttp:HTTPService=new HTTPService; serviceHttp.url="http://localhost/application/listes.php"; serviceHttp.resultFormat="e4x"; serviceHttp.method="POST"; serviceHttp.addEventListener(FaultEvent.FAULT,ResultatKo) serviceHttp.addEventListener(ResultEvent.RESULT,ResultatOk) serviceHttp.send() } public function ResultatOk(e:ResultEvent):void{ var resultatXML:XML=e.result as XML; listecomposants.dataProvider=resultatXML.composant; } public function ResultatKo(e:FaultEvent):void{ Alert.show("Erreur !!!").width=300; }
rappelons que tous les fichiers sont dans le même répertoire
Partager