2 Replies Latest reply on Apr 28, 2011 1:54 PM by [Jongware]

    Loading xml data into the datagrid

    suryapavan.85

      Hi all,

      I'm trying to learn Flex. I have a small doubt in loading the datagrid from the xml response (from php script)


      mxml code:



      <mx:DataGrid id="dataGrid" x="69" y="250">

      <mx:columns>

      <mx:DataGridColumn headerText="Name" dataField="name"/>

      <mx:DataGridColumn headerText="Age" dataField="age"/>

      <mx:DataGridColumn headerText="Location" dataField="location"/>

      </mx:columns>

      </mx:DataGrid>


      <mx:HTTPService resultFormat="e4x" result="getDataCallback(event)" id="getDataHttp" url="http://localhost/test/getData.php" method="POST"></mx:HTTPService>

      <mx:Button click="getDataHttp.send();" label="Load Data" x="379" y="268"></mx:Button>



      <mx:Script>

      <![CDATA[

      import mx.collections.ArrayCollection;

      import mx.rpc.events.ResultEvent;

      import mx.controls.Alert;

      [Bindable] public var mydata:XMLList = new XMLList();

      function getDataCallback(event:ResultEvent):void{

      trace(event.result.data.info);

      mydata = event.result.data.info;

      dataGrid.dataProvider = mydata;

      }


      ]]>

      </mx:Script>


       

      PHP Script


      <?php
      $xml
      = "<?xml version=\"1.0\" ?><data>";
      $xml .= "
      <info><name>name1</name><age>26</age><location>location1</location></info>";
      $xml .= "
      <info><name>name2</name><age>27</age><location>location2</location></info>";
      $xml .= "
      </data>";
      header("content-type:text/xml");
      echo $xml;



      But the data is not being loaded into the datagrid. Please anyone help me out ..

      Thanks in advance

      -Pavan