cc.loader.getXMLHttpRequest not working on Simulator & windows native

cc.loader.getXMLHttpRequest not working on Simulator & windows native
0.0 0

#1

Hi, anybody know why this is not working?

I have a button that calls send() and then I put the responseText on a label. It works great on web browser but on Simulator and Windows native, the event is undefined.

xhrCallback: function (event) {
        this.canvas = cc.director.getScene().getChildByName('Canvas');
        if(typeof event == 'undefined'){
            this.canvas.getChildByName('label').getComponent(cc.Label).string = "event is undefined";
            return;
        }
        if (event.currentTarget.readyState === 4 && (event.currentTarget.status >= 200 && event.currentTarget.status < 300)) {
            this.canvas.getChildByName('label').getComponent(cc.Label).string = event.currentTarget.responseText;
        }
    },

    send: function () {
        var xhr = cc.loader.getXMLHttpRequest();
        xhr.open("GET", "https://httpbin.org/get", true);
        xhr.onreadystatechange = this.xhrCallback;
        xhr.send();
    }

#2

Found and example on the documentation and it works:

http://cocos2d-x.org/docs/editors_and_tools/creator-chapters/scripting/network/index.html