//Test Data transferPublic data ():void{ This. http =NewLaya.httprequest ();//new A HttpRequest class This. Http.once (Laya.Event.PROGRESS, This, This. onprogress);//in data transmission This. Http.once (Laya.Event.COMPLETE, This, This. OnComplete);//when the data transfer is complete, a data is returned This. Http.once (Laya.Event.ERROR, This, This. OnError);//return after data transfer failure //How the post data is spelled This. Http.send ("http://localhost/post.php", ' name=guifa&pwd=123456 ', ' post ', ' text '); //How get data is spelled This. Http.send ("http://localhost/post.php?name=guifa&pwd=12345678",NULL, ' get ', ' text '); }
//Datamethod of triggering in data transferPublic OnProgress (E:any):void{Console.log (e); } //when the data transfer is complete, a data is returnedPublic OnComplete (E:any):void{ varTextArea:Laya.Text =NewLaya.text ();//Create a text
This.http.data is the data value Laya.net.LocalStorage.setItem ("name") returned by the PHP backend server. This. Http.data);//Store user information locally, equivalent to a cookieLaya.net.LocalStorage.setItem ("name", "guifa2014");//Modify local User information varName =laya.net.localstorage.getitem ("name");//get local User information varURL = This. getquerystring ("url");//methods to get URL parametersTextarea.text = "Cookie:" +name+ "url parameter:" +URL; Textarea.x= 80; TEXTAREA.Y= 80; Laya.stage.addChild (TextArea); //add text to the stage } //return after data transfer failurePublic OnError (E:any):void{Console.log (e); }
// get the parameters inside the URL Public getquerystring (name): any { varnew RegExp ("(^|&) + name +" = ([^&]*) (&|$) "); var r = window.location.search.substr (1). Match (reg); if (r!=null) return r[2]; // Note that you can't use the Unescape method inside JS. return NULL ;}
Above is the code section of TS
The following is part of the server-side test
var $_post [' name ']; if (! name) {echo 201; Exit ; } echo 200; exit; // PHP returns with Echo
For details, see official: Http://layaair.ldc.layabox.com/demo/?Network_POST
Laya how to post and get data to the background PHP server