Flash: XML and LoadVars to send data in POST

Here is a great way to send POST data to a Web Server. We will use two objects: a LoadVars object to send and to receive an XML object (in case we expect a return formatted XML document). Use the LoadVars object in Flash is useful for creating run-time properties that will be seen as POST variables for both the ability to specify the delivery method: POST or GET.

First of all we create the LoadVars object that will be used to ship:

1
LoadVars = new LoadVars ( ) ; var s_lv: LoadVars = new LoadVars ();

To this we add the POST variables in a very simple:

1
2
; s_lv. title = "Hello";
; s_lv. subtitle = "Hello World";

Prepare the object that receives the response from the Web Server (in stdout) - if you just make a PHP echo:

1
2
XML = new XML ( ) ; var r_xml: XML = new XML ();
= true ; r_xml. ignoreWhite = true;

At this point we can do is send:

1
"http://miodominio.com/miapagina.php" , r_xml , "POST" ) ; s_lv. sendAndLoad ("http://miodominio.com/miapagina.php" r_xml, "POST");

The sendAndLoad () method of the LoadVars object is very ultile as it allows you to specify the object return (in this case our XML object r_xml) and the shipping method (in our case POST).
Finally just put on hold:

1
2
3
4
5
( success : Boolean ) { r_xml. onLoad = function (success: Boolean ) {
success ) { if (success) {
/ / Processing results
}
};

There are no comments for this post

Leave a comment

XHTML TAG PERMIT: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> INSERTION CODE:
 <pre></pre> // blocco generico <code></code> // blocco generico [cc_actionscript][/cc_actionscript] // Actionscript [cc_actionscript3][/cc_actionscript3] // Actionscript 3 [cc_css][/cc_css] // CSS Style Sheet [cc_html][/cc_html] // HTML [cc_js][/cc_js] // Javascript [cc_objc][/cc_objc] // Objective-C [cc_php][/cc_objc] // PHP [cc_sql][/cc_sql] // SQL 


Stop SOPA