php. null,php 参数 null

博客作者遇到一个Flex HttpService访问PHP时无法正确传递参数的问题。尽管Flex能够成功访问PHP,但传递的id参数在PHP端显示为null。作者尝试了多种解决办法,包括设置变量初始值和直接在URL中携带参数,但问题仍未解决。社区成员提供了可能的解决方案,建议检查变量赋值时机和直接在send方法中传递参数。
摘要由CSDN通过智能技术生成

场景:flex Httpservice 访问php 参数替null

flex Httpservice 访问php 参数为null

看cookbook到了数据访问。开始便给出了Httpservice示例,我按着书中所说布置了工程,把代码copy到工程里:

这是flex的代码:

id="service"

result="serviceResult(event)" fault="serviceFault(event)"

method="GET" contentType="application/xml"

useProxy="false">

{requestedId}

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);

}

}

]]>

这是PHP后端代码:

$id = $_GET["id"];

echo(''.$id.'ok30');

?>

flex通过localhost:18000访问index.php,同时向php用get形式传送一个key为id的值。实际运行后,flex的确可以访问到index.php,但问题是只能取到echo(''.$id.'ok30');中的name与age的值,由flex传过去的id为null。

php端通过localhost:18000/index.php?id=111 证明id是可以获取的,无错。

请大家帮忙找找原因,不胜感激!

------解决方案--------------------

至于FLEX传过去的ID没拿到,估计是requestedId 还没拿到值,你可以试试先给这个变量一个值

private var requestedId:String = “test”;

建议你不要用

{requestedId}

这种方式,

直接将参数放到send方法里传过去就好了,例如service.send({id: requestedId});

------解决方案--------------------

在send之前改变url也行

直接在URL后面带   ?id=变量  那样稳的传的出去

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值