flex 如何用HTTPService 与后台交互数据

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[0.72, 1.0]" backgroundGradientColors="[#FFFFFF, #FFFFFF]">
	
	<mx:HTTPService 
  		showBusyCursor="true"  
  		id="loginSrv" 
  		result="doResult();"  
  	    method="GET"
  		url="http://localhost:8080/UserManager/checkUser.do"> 
 		<mx:request> 
 			<userName>  
 				{txtname.text} 
 			</userName> 
 			<password> 
				{txtpwd.text}
 			</password> 
 		</mx:request> 
	</mx:HTTPService> 
	<mx:HTTPService 
  		showBusyCursor="true"  
  		id="loadUsers"  
  	    method="GET" result="users = event.result.users.user"
  		url="http://localhost:8080/UserManager/loadAllUsers.do">  
	</mx:HTTPService> 
		<mx:Script>
		<![CDATA[
		    import mx.controls.Alert;
            import mx.utils.ObjectUtil;
            import mx.collections.ArrayCollection; 
            
            [Bindable]
            var users:ArrayCollection=new ArrayCollection();
			internal function doResult():void
			{ 
				var returnValue:String=loginSrv.lastResult.result.msg; 
       			if(returnValue=="sucess") 
  				{   
  					login.visible=false;  
  					loadUsers.send();
  					userList.visible=true;  					
        		}  
 				else 
   				{  
					Alert.show("登录失败","提示信息",Alert.OK,this,null,null,Alert.YES); 
              	}
			} 
		    private function index_sortCompareFunc(itemA:Object, itemB:Object):int {
                // Make sure itemA has an "index" property.
                if (!itemA.hasOwnProperty("id")) {
                    itemA.index = null;
                }
                // Make sure itemB has an "index" property.
                if (!itemB.hasOwnProperty("id")) {
                    itemB.index = null;
                }
                // Perform a numeric sort.
                return ObjectUtil.numericCompare(itemA.index, itemB.index);
            } 
		]]>
	</mx:Script>
	<mx:Panel id="login" x="285.5" y="127" width="341" height="238" layout="absolute" fontFamily="Arial" fontSize="13" color="#3C280B" borderStyle="none" borderColor="#CC0B0B" cornerRadius="10" alpha="0.64">
		<mx:TextInput id="txtname" x="101" y="34" width="172" displayAsPassword="true" editable="true" enabled="true"/>
		<mx:Button x="92" y="130" label="登录" labelPlacement="top" enabled="true" click="loginSrv.send();"/>
		<mx:Button x="183" y="130" label="取消"/>
		<mx:TextInput id="txtpwd" x="101" y="75" width="172" displayAsPassword="true" editable="true" enabled="true"/>
		<mx:Label x="44" y="36" text="帐号:" width="49" height="20" enabled="true"/>
		<mx:Label x="44" y="77" text="密码:" width="49" height="20" enabled="true"/>
	</mx:Panel>
	<mx:Panel id="userList" x="181.5" y="98" width="576" height="311" layout="absolute" visible="false">
		<mx:DataGrid x="0" y="0" width="556" height="271" sortableColumns="true" dataProvider="{users}" editable="true" enabled="true">
			<mx:columns>
			    <mx:DataGridColumn headerText="编号" dataField="id"  />
				<mx:DataGridColumn headerText="姓名" dataField="userName" />
				<mx:DataGridColumn headerText="密码" dataField="password"/>
				<mx:DataGridColumn headerText="邮件" dataField="email"/>
				<mx:DataGridColumn headerText="地址" dataField="address"/>
			</mx:columns>
		</mx:DataGrid>
	</mx:Panel>
</mx:Application>
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值