Httpservice
Páginas: 11 (2611 palabras)
Publicado: 6 de julio de 2012
You can use an HTTPService component with any kind of server-side technology, including PHP pages, ColdFusion Pages, JavaServer Pages (JSPs), Java servlets, Ruby on Rails, and Microsoft ASP pages.
For API reference information about the HTTPService component, see mx.rpc.http.mxml.HTTPService.
Working with PHP and SQL data
You can use a Flex HTTPService componentin conjunction with PHP and a SQL database management system to display the results of a database query in a Flex application and to insert data into a database. You can call a PHP page with GET or POST to perform a database query. You can then format the query result data in an XML structure and return the XML structure to the Flex application in the HTTP response. When the result has beenreturned to the Flex application, you can display it in one or more user interface controls.
MXML code
The Flex application in the following example calls a PHP page with the POST method. The PHP page queries a MySQL database table called users. It formats the query results as XML and returns the XML to the Flex application, where it is bound to the dataProvider property of a DataGrid control anddisplayed in the DataGrid control. The Flex application also sends the user name and e-mail address of new users to the PHP page, which performs an insert into the user database table.
-------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
-------------------------------------------------
<mx:Applicationxmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
-------------------------------------------------
xmlns="*" creationComplete="send_data()">
-------------------------------------------------
<mx:Script>
-------------------------------------------------
<![CDATA[
-------------------------------------------------private function send_data():void {
-------------------------------------------------
userRequest.send();
-------------------------------------------------
}
-------------------------------------------------
]]>
-------------------------------------------------</mx:Script>
-------------------------------------------------
<mx:Form x="22" y="10" width="493">
-------------------------------------------------
<mx:HBox>
-------------------------------------------------
<mx:Label text="Username"/>
-------------------------------------------------<mx:TextInput id="username"/>
-------------------------------------------------
</mx:HBox>
-------------------------------------------------
<mx:HBox>
-------------------------------------------------
<mx:Label text="Email Address"/>
-------------------------------------------------<mx:TextInput id="emailaddress"/>
-------------------------------------------------
</mx:HBox>
-------------------------------------------------
<mx:Button label="Submit" click="send_data()"/>
-------------------------------------------------
</mx:Form>-------------------------------------------------
<mx:DataGrid id="dgUserRequest" x="22" y="128" dataProvider="{userRequest.lastResult.users.user}">
-------------------------------------------------
<mx:columns>
-------------------------------------------------
<mx:DataGridColumn headerText="User ID" dataField="userid"/>...
Leer documento completo
Regístrate para leer el documento completo.