代码:
properties: {
mylab: cc.Label,
mytext:0,
},
start(){
var url = “http://127.0.0.1:8081/?name=1&password=2”;
var xhr = new XMLHttpRequest();
// this.response=“aaab”;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
this.mytext = xhr.responseText;
console.log(this.mytext);//**这里输出正常**
}
};
xhr.open("GET", url, true);
cc.log(this.mytext);// **这里无法获得数据**
},
////
现在想在LABEL中显示返回的数据,死活不出来
this.mylab.string=this.mytext;
但是在浏览器中能console,看得到 返回的数据。
看了网上资料,好像说是异步执行出现的问题,现在应该怎么获取?