2013-01-02 35 views
0

我的項目出現問題,我試圖用XML文件填充列表,我從PHP文件中獲取。我用httpservice調用php文件,這個文件返回xml數據。現在看起來有問題,但我沒有得到任何錯誤。我只是知道調試後,我的XMLListCollection保持爲空。httpService和XMLListCollection

這裏是我的代碼:

<?xml version="1.0" encoding="utf-8"?> 
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
       xmlns:s="library://ns.adobe.com/flex/spark" 
       xmlns:mx="library://ns.adobe.com/flex/mx" 
       xmlns:components="components.*" 
       creationComplete="httpService.send()"> 

    <s:layout> 
     <s:VerticalLayout paddingTop="20" gap="20" 
          horizontalAlign="center" /> 
    </s:layout> 
    <fx:Script> 
     <![CDATA[ 
      import mx.rpc.events.ResultEvent; 
      import mx.collections.ArrayCollection; 
      import mx.collections.XMLListCollection; 

      import mx.rpc.events.FaultEvent; 
      import mx.controls.Alert; 
      private var alert:Alert; 

      private function httpService_fault(evt:FaultEvent):void { 
       var title:String = evt.type + " (" + evt.fault.faultCode + ")"; 
       var text:String = evt.fault.faultString; 
       alert = Alert.show(text, title); 
       Bezoekers.removeAll(); 
      } 

      private function httpService_result(evt:ResultEvent):void { 
       var xmlList:XMLList = XML(evt.result).bezoekers.bezoeker; 
       Bezoekers = new XMLListCollection(xmlList); 

      } 






     ]]> 
    </fx:Script> 
    <fx:Declarations> 
     <s:HTTPService id="httpService" 
         url="http://localhost/projectnieuw/src/data/bezoekersList.php" 
         resultFormat="e4x" 
         fault="httpService_fault(event);" 
         result="httpService_result(event)" /> 
     <!--<fx:Model id="lijstAlleLeden" source="httpAlleLeden" />--> 
     <!--<s:ArrayCollection id="acBezoekers" source="{Bezoekers}"/>--> 
     <s:XMLListCollection id="Bezoekers"/> 
    </fx:Declarations> 





    <components:Heading/> 
    <s:HGroup gap="50"> 

     <components:BezoekersList bezoekerList="{Bezoekers}" /> 
     <components:ReservationForm/> 

    </s:HGroup> 

</s:Application> 

我似乎並沒有得到什麼是錯的。

預先感謝來自比利時

問候

回答

0

您的XMLListCollection仍然意味着Bezoekers = new XMLListCollection(xmlList);給予它空。所以首先嚐試追蹤服務器端的結果不爲空。爲了測試服務器端的響應,你有一個竅門是,在Web瀏覽器中打開你的HTTPService的URL,並在Web瀏覽器中獲取XML數據。如果獲得成功,請嘗試resultFormat="xml"而不是resultFormat="e4x"並閱讀documentation of HTTPService's result Type以瞭解如何使用它。它也有一些針對XML的案例到案例的解決方案。

也許這將幫助你......

+0

我已經測試了我在瀏覽器中的HTTPService的URL,它返回的XML數據。我已將resultFormat更改爲xml,但Bezoekers保留爲空。我現在要閱讀文檔。 – user1941525