//æµè¯æ°æ®ä¼ è¾
public data():void{
this.http = new Laya.HttpRequest(); //newä¸ä¸ªHttpRequestç±»
this.http.once(Laya.Event.PROGRESS,this,this.onProgress); //æ°æ®ä¼ è¾ä¸
this.http.once(Laya.Event.COMPLETE,this,this.onComplete); //æ°æ®ä¼ è¾å®æåï¼ä¼è¿åä¸ä¸ªdata
this.http.once(Laya.Event.ERROR,this,this.onError); //æ°æ®ä¼ è¾å¤±è´¥åè¿å
//postæ°æ®çåæ³
this.http.send("
http://localhost/post.php",'name=guifa&pwd=123456', 'post', 'text');
//getæ°æ®çåæ³
this.http.send("
http://localhost/post.php?name=guifa&pwd=12345678",null,'get', 'text');
}
//æ°æ®æ°æ®ä¼ è¾ä¸è§¦åçæ¹æ³
public onProgress(e:any):void{
console.log(e);
}
//æ°æ®ä¼ è¾å®æåï¼ä¼è¿åä¸ä¸ªdata
public onComplete(e:any):void{
var textArea:Laya.Text = new Laya.Text(); //å建ä¸ä¸ªææ¬
//this.http.dataå°±æ¯phpåå°æå¡å¨è¿åçdataå¼
laya.net.LocalStorage.setItem("name",this.http.data); //åå¨ç¨æ·ä¿¡æ¯å°æ¬å°ä¸ï¼ç¸å½äºcookie
laya.net.LocalStorage.setItem("name","guifa2014"); //ä¿®æ¹æ¬å°ç¨æ·ä¿¡æ¯
var name =laya.net.LocalStorage.getItem("name"); //è·åæ¬å°ç¨æ·ä¿¡æ¯
var url = this.GetQueryString("url"); //è·åurlåæ°çæ¹æ³
textArea.text = "cookie:"+name+"urlåæ°:"+url;
textArea.x = 80;
textArea.y = 80;
Laya.stage.addChild(textArea); //æ·»å ææ¬å°èå°ä¸
}
//æ°æ®ä¼ è¾å¤±è´¥åè¿å
public onError(e:any):void{
console.log(e);
}
//è·åurléé¢çåæ°
public GetQueryString(name):any
{
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
var r = window.location.search.substr(1).match(reg);
if(r!=null)
return r[2]; //注æè¿éä¸è½ç¨jséé¢çunescapeæ¹æ³
return null;
}
ä¸é¢æ¯tsç代ç é¨å
ä¸é¢æ¯æå¡å¨ç«¯æµè¯çé¨å
var name = $_POST['name'];
if(!name){
echo 201;exit;
}
echo 200;exit; //phpç¨echoè¿å