cocos如何使用XMLHttpRequest返回的数据

代码:
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,看得到 返回的数据。
看了网上资料,好像说是异步执行出现的问题,现在应该怎么获取?

这就是异步问题啊,第二个log执行完成时,http请求还没完成的,毕竟请求是需要时间的,而这代码,不会等待你http请求完成才执行你得第二个cc.log打印语句,解决办法,要么你就在回调中做接下来的处理,要么就用Promise改一下

异步真头疼啊,搞了一天,好不容易啊