In actionscript, is there a jQuery ajax function, $ .post ()?

I want to save user work logs by accessing a log script file (e.g. log.php) with a message or parameter from my flash application.
Flash is a web application, not a desktop application.

In jQuery, javascript can access other files on a website using the following code:

$.post("test.php", {a: 1, b: 2}, function(data) { console.log(data); }); 

$. post document:
http://api.jquery.com/jQuery.post/

I think the following actionscript is equivalent to jQuery $ .post ().
Does this code cause any problems that are not caused by jQuery $ .post ()?
Is there a simpler and shorter way to do this?

 var loader:URLLoader = new URLLoader(); loader.addEventListener(Event.COMPLETE, function():void { trace(loader.data); }); var variables:URLVariables = new URLVariables(); variables.a = 1; variables.b = 2; var request:URLRequest = new URLRequest("test.php"); request.data = variables; request.method = URLRequestMethod.POST; try { loader.load(request); } catch (error:Error) { trace("failed"); } 
+4
source share
2 answers

I think there are 3 more ways to do the same ...

  1. httpService 2. WebService 3. RPC 

The first two are identical, there is simply a difference in the protocol, and, in my opinion, the last option is the best option. This is 8-10 times faster than the other two. You can find all the details on the Adobe website.

0
source

I made one for you with how you DO .

 function HTTPPost(_URL:String,_UVar:Object,_UEvent:Object){ var _Loader:URLLoader=new URLLoader(); _Loader.addEventListener(Event.COMPLETE,function():void{ if(_UEvent.hasOwnProperty("_Done")) _UEvent._Done(_Loader.data) }); _Loader.addEventListener(IOErrorEvent.IO_ERROR,function():void{ if(_UEvent.hasOwnProperty("_Error")) _UEvent._Error(_Loader.data) }); var _Variables:URLVariables=new URLVariables(); for(var i in _UVar){ _Variables[i]=_UVar[i] } var _Request:URLRequest=new URLRequest(_URL); _Request.data=_Variables; _Request.method=URLRequestMethod.POST; try{ _Loader.load(_Request); }catch(error:Error){ trace("Failed."); } } //HTTPPost(File URL, post data and event functions) 

Then you use it like this:

 HTTPPost("URL",{"Variable_1":"Value"},{ "_Done":function(Message){ trace(Message)//print what URL file prints }, "_Error":function(Message){ trace(Message)//print an HT with error info } }) 
0
source

All Articles