jeudi 26 janvier 2017

Simple ActionScripts3 JSON send to PHP

I'm trying to send a simple json data "{"DATA1":"111","DATA2":"222"}" to PHP from ActionScripts3, There is no error and warning but nothing happened in PHP.

AS3:

import flash.net.*;
import flash.events.Event;

 function JSON_send():void 
 { 
       var url:String = "http://localhost/as_json_write.php"; 

       var JSON_strings:String = "DATA1="+"111"+"&DATA2="+"222"; 

       var postParams:URLVariables = new URLVariables(JSON_strings);

       var request:URLRequest = new URLRequest(url);
        request.method = URLRequestMethod.POST;
        request.data = postParams;

       var urlLoader:URLLoader = new URLLoader();

        urlLoader.addEventListener(Event.COMPLETE, onLoaderComplete);
        urlLoader.load(request);

}

function onLoaderComplete( event:Event ):void
{
       var urlLoader2:URLLoader = event.target as URLLoader;
}

JSON_send();

PHP:

<?php

ob_start();
var_dump($_POST['myObject']);
print_r($_POST);
$content = ob_get_contents();
ob_end_clean();
$json_data = json_decode($content);
echo $json_data;

?>

Aucun commentaire:

Enregistrer un commentaire