Laya how to post and get data to the background PHP server

Source: Internet
Author: User
Tags php server

//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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.