5 Replies Latest reply on Oct 9, 2009 2:42 AM by flex_n00b

    Problems in HTTPService with PHP

    flex_n00b

      Hi,

       

      This is the Flex code that I have-

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="do_work()">
         
          <mx:HTTPService id="find_college" fault="errorhandler(event)"   result="resulthandler(event)" showBusyCursor="true" method="GET"  useProxy="false" >
             
          </mx:HTTPService>
         
         
          <mx:Script>
         
              <![CDATA[
             
              import mx.collections.ArrayCollection;
              import mx.rpc.events.ResultEvent;
              import mx.controls.Alert;
              import mx.rpc.events.FaultEvent;
             
             
              [Bindable]private var collegeData:ArrayCollection = new ArrayCollection();
             
             
              private function do_work():void
              {
                  find_college.url="http://localhost/take2.php?name=pqr"
                              find_college.send();
              }
             
             
                  private function errorhandler(e:FaultEvent):void
              {
                  Alert.show(e.fault.message,"Server Error");
              }
             
             
             
             
                  private function resulthandler(e:ResultEvent):void
              {
                      collegeData = e.result.mydata;
                     
              }
              ]]>
          </mx:Script>
          <mx:ComboBox id="college_list" x="464" y="229" dataProvider="{collegeData}" labelField="name">
              </mx:ComboBox>
             
             
         
      </mx:Application>

       

       

       

       

      -----

       

      and the take2.php contains-

       

      echo("<mydata>".$_GET['name']."</mydata>");

       

       

       

      ---

       

      Problem is that the ComboBox does not fill with the value of the GET variable, it says transferring from localhost indefinitely.

        • 1. Re: Problems in HTTPService with PHP
          Madhav Subedi Level 4

          try changing your php code as:

           

          echo("<mydata><name>".$_GET['name']."</name></mydata>");

           

          right now, you are providing the labelfield as NAME but your collection doesnot contain the NAME field.

          • 2. Re: Problems in HTTPService with PHP
            flex_n00b Level 1

            I tried that, but same problem persists

            • 3. Re: Problems in HTTPService with PHP
              drillnaut Level 1

              Not sure I can help but here is how I do it when fighting working with xml.  First off , declare the resultFormat of the HTTPService to be "e4x".  Then make an xml list of the result , grab the name from the list objects , stuff that name into a new object , then finally stuff that object into the collegeData arraycollection.  It may be a little roundabout but it works for me ... sometimes.

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="do_work()">
                 
              <mx:HTTPService id="find_college" resultFormat="e4x" fault="errorhandler(event)"   result="resulthandler(event)" showBusyCursor="true" method="GET"  useProxy="false" >
              </mx:HTTPService>
                 
              <mx:Script>
                  <![CDATA[
                     
                      import mx.collections.ArrayCollection;
                      import mx.rpc.events.ResultEvent;
                      import mx.controls.Alert;
                      import mx.rpc.events.FaultEvent;
                     
                      [Bindable]private var collegeData:ArrayCollection = new ArrayCollection();
                     
                      private function do_work():void
                      {
                          find_college.url="http://localhost/take2.php?name=pqr"
                          find_college.send();
                      }

               

                     private function errorhandler(e:FaultEvent):void
                      {
                          Alert.show(e.fault.message,"Server Error");
                      }
                     
                      private function resulthandler(e:ResultEvent):void
                      {
                              var resultXML:XML = e.result as XML;

                              var nameList:XMLList = resultXML..name;

               

                              for each(var nameXML:XML in nameList)

                              {

              //                   var name:String = nameXML.name.toString();

              //                   or maybe its

                                  var name:String = nameXML.toString();

                                  var object:Object = new Object();

                                  object['name'] = name;

                                  collegeData.addItem(object);
                               }

                      }
                      ]]>
                  </mx:Script>
                  <mx:ComboBox id="college_list" x="464" y="229" dataProvider="{collegeData}" labelField="name" />

              </mx:Application>

               

              Message was edited by: drillnaut Accidently hit enter , my bad.

              1 person found this helpful
              • 4. Re: Problems in HTTPService with PHP
                satoshi.ara

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="do_work()">

                    <mx:HTTPService id="find_college"
                     fault="errorhandler(event)"  
                     result="resulthandler(event)"
                     resultFormat="xml"
                     showBusyCursor="true"
                     method="GET" 
                     useProxy="false" >
                    </mx:HTTPService>
                   
                   
                    <mx:Script>
                        <![CDATA[
                       
                        import mx.collections.ArrayCollection;
                        import mx.rpc.events.ResultEvent;
                        import mx.controls.Alert;
                        import mx.rpc.events.FaultEvent;
                       
                        [Bindable]private var collegeData:XMLList = new XMLList();
                       
                        private function do_work():void
                        {
                            find_college.url="http://localhost/take2php?name=pqr"
                                        find_college.send();
                        }
                       
                        private function errorhandler(e:FaultEvent):void
                        {
                            Alert.show(e.fault.message,"Server Error");
                        }
                       
                        private function resulthandler(e:ResultEvent):void
                        {
                          collegeData = XML(e.result).mydata;
                        }
                        ]]>
                    </mx:Script>
                    <mx:ComboBox id="college_list" x="464" y="229" dataProvider="{collegeData}" labelField="name">
                    </mx:ComboBox>
                </mx:Application>

                 

                /* ----------------------------------------------------------------------------------------- -----------*/

                /* take2.php

                /* ----------------------------------------------------------------------------------------- -----------*/

                <?php
                $x  = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
                $x .= "<xmlbody>";
                $x .= "<mydata>".$_GET['name']."</mydata>";
                $x .= "<mydata>".$_GET['name']."</mydata>";
                $x .= "<mydata>".$_GET['name']."</mydata>";
                $x .= "</xmlbody>";

                header("Content-Type: text/xml");
                header("Content-Length: ".strlen($x));
                print($x);

                • 5. Re: Problems in HTTPService with PHP
                  flex_n00b Level 1

                  Thanks for the last post, it worked