I am trying to send a variable from Flash to PHP, and then echo it back to flash (ignore function names etc. for now; just trying to troubleshoot the basics first).
Flash file (call it test.as):
var myLoader:URLLoader = new URLLoader();
var file_path:String = "get_this.php";
var myRequest:URLRequest = new URLRequest(file_path);
myRequest.method = URLRequestMethod.POST;
var memberInfo:URLVariables = new URLVariables();
myLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
memberInfo.member_id = 10;
myRequest.data = memberInfo;
myLoader.addEventListener(Event.COMPLETE, onXMLLoad);
myLoader.load(myRequest);
function onXMLLoad(event:Event)
{
trace(myLoader.data);
}
PHP file (get_this.php):
<?php
header('Content-Type: text/xml');
echo "<?xml version='1.0' encoding='UTF-8'?>";
$member_id = $_POST['member_id'];
echo "member_id=$member_id";
?>
However, when I do this, the trace on "myLoader.data" returns a massive string consisting of every single word in the entire PHP file, including comments, which are omitted on this post (C++/Flash style comments (//) ), with some random numbers separated by % signs. This surely is an easy fix, but I am rather new to PHP (and not too experienced with Flash yet), so if someone could help me out I would be very appreciative.
Firstly, test your PHP on the browser and see if its working as expected. Secondly, your complete function should look like this:
function onXMLLoad(event:Event)
{
var variables:URLVariables = new URLVariables( event.target.data );
trace(variables.member_id);
}
Hope this answers your question.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.