本文介绍了httpService 和 XMLListCollection的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目有问题,我尝试用从 php 文件中获取的 xml 数据填充列表.我使用 httpservice 调用 php 文件,该文件返回 xml 数据.现在似乎有问题,但我没有收到任何错误.调试后我才知道我的 XMLListCollection 仍然为空.

I have a problem with my project where I try to fill a list with my xml data that I get out of an php file. I call the php file with a httpservice and this file returns xml data. Now it seems that there is a problem, but I don't get any error. I just know after debugging that my XMLListCollection remains null.

这是我的代码:

<?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>

我似乎不明白出了什么问题.

I don't seem to get what's wrong.

提前致谢

来自比利时的问候

推荐答案

你的 XMLListCollection 保持 null 意味着 Bezoekers = new XMLListCollection(xmlList); 给它 null.所以首先尝试从服务器端跟踪结果不是空的.要测试服务器端响应,您有一个技巧是,在网络浏览器中打开您的 HTTPService 的 URL 并在网络浏览器中获取 XML 数据.如果成功,请尝试 resultFormat="xml" 而不是 resultFormat="e4x" 并阅读 HTTPService 的结果类型文档 了解如何使用它.它还有一些针对 XML 的个案解决方案.

your XMLListCollection remains null means Bezoekers = new XMLListCollection(xmlList); gives to it null. so first of all try to trace that result was not null from server-side. To test server-side response, you have one trick is that, open your HTTPService's URL in web-browser and get XML data in Web-browser. if get success then try resultFormat="xml" instead of resultFormat="e4x" and read documentation of HTTPService's result Type to know how to use it. it has also some case-to-case basis solution for XML.

愿这对你有帮助...

这篇关于httpService 和 XMLListCollection的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 16:40