flex Httpservice 访问php 参数为null

Begin_Game 2009-07-22 09:45:02
看cookbook到了数据访问。开始便给出了Httpservice示例,我按着书中所说布置了工程,把代码copy到工程里:
这是flex的代码:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical">
<mx:HTTPService url="http://localhost:18000/index.php"
id="service"
result="serviceResult(event)" fault="serviceFault(event)"
method="GET" contentType="application/xml"
useProxy="false">
<mx:request xmlns="">
<id>{requestedId}</id>
</mx:request>
</mx:HTTPService>
<mx:Script>
<![CDATA[
import mx.rpc.events.FaultEvent;
import mx.rpc.events.ResultEvent;
import mx.controls.Alert;

[Bindable]
private var requestedId:String;

//trace the result of the service out
private function serviceResult(event:Event):void {
trace(service.lastResult.name);
}
// in the event that the service faults or times out
private function serviceFault(event:Event):void {
trace('broken service');
}
private function callService():void {
try{
requestedId = input.text;
service.send();
}catch(e:Error){
Alert.show(e.message);
}
}
]]>
</mx:Script>
<mx:TextInput id="input"/>
<mx:Button label="get user name" click="callService()"/>
<mx:Text text="{service.lastResult.id}"/>
<mx:Text text="{service.lastResult.name}"/>
<mx:Text text="{service.lastResult.age}"/>
</mx:Application>


这是PHP后端代码:

<?php
$id = $_GET["id"];
echo('<id>'.$id.'</id><name>ok</name><age>30</age>');
?>


flex通过localhost:18000访问index.php,同时向php用get形式传送一个key为id的值。实际运行后,flex的确可以访问到index.php,但问题是只能取到echo('<id>'.$id.'</id><name>ok</name><age>30</age>');中的name与age的值,由flex传过去的id为null。
php端通过localhost:18000/index.php?id=111 证明id是可以获取的,无错。
请大家帮忙找找原因,不胜感激!
...全文
460 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
howei777 2012-05-15
  • 打赏
  • 举报
回复
你把 contentType="application/xml" 这个含义不清的
zgycsmb 2010-12-02
  • 打赏
  • 举报
回复
楼主,我运行了你的代码,发现 id没有传到php页面,这个问题,你现搞定了吗?
xxcn2007 2009-07-24
  • 打赏
  • 举报
回复
可能是php输出的问题,你现在输出的并不是xml
kukulu00 2009-07-24
  • 打赏
  • 举报
回复
在send之前改变url也行
直接在URL后面带 ?id=变量 那样稳的传的出去
herowach 2009-07-23
  • 打赏
  • 举报
回复
至于FLEX传过去的ID没拿到,估计是requestedId 还没拿到值,你可以试试先给这个变量一个值
private var requestedId:String = “test”;
建议你不要用
<mx:request xmlns="">
<id>{requestedId}</id>
</mx:request>这种方式,
直接将参数放到send方法里传过去就好了,例如service.send({id: requestedId});
herowach 2009-07-23
  • 打赏
  • 举报
回复
可能是你的id里面有特殊字符造成的,你换成个普通的字符串试试

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧