mx:HTTPService的使用非常简单,我写了一个简单的例子,代码如下:

<?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" minWidth="955" minHeight="600" creationComplete="application1_creationCompleteHandler(event)">
	<s:layout>
		<s:BasicLayout/>
	</s:layout>
	<fx:Script>
		<![CDATA[
			import mx.controls.Alert;
			import mx.events.FlexEvent;
			import mx.rpc.events.FaultEvent;
			import mx.rpc.events.ResultEvent;
			import mx.utils.UIDUtil;
			
			protected function application1_creationCompleteHandler(event:FlexEvent):void
			{
				service.url = "http://localhost:8080/demo/Test1.action?rnd=" + new Date().toString();
				service.send();
			}


			protected function service_resultHandler(event:ResultEvent):void
			{
				Alert.show(String(event.result));
			}


			protected function service_faultHandler(event:FaultEvent):void
			{
				Alert.show("请求异常");
			}

		]]>
	</fx:Script>
	<fx:Declarations>
		<mx:HTTPService  />
	</fx:Declarations>
	
</s:Application>

 

通过service.url指定一个请求的地址,我添加了一个动态的参数,可以保证每次请求的都是最新的页面,防止页面被缓存

service.send();方法开始调用这个请求.

result事件是在调用成功后执行,fault事件是在调用失败后执行

resultFormat属性为text的时候,在result事件,可以通过String(event.result)得到请求页面的输出结果

相关文章:

  • 2021-05-24
  • 2021-09-11
  • 2021-09-01
  • 2021-12-03
  • 2022-01-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-06-25
  • 2021-07-06
  • 2021-09-24
  • 2022-12-23
  • 2021-08-13
  • 2021-10-18
相关资源
相似解决方案