Ajax 调用接口后, 如何在回调函数里面 切换场景

ajax 调用接口后, 如何在回调函数里面 切换场景


    xhr.onreadystatechange = function () {

        if(xhr.readyState == 4 && xhr.status == 200){
            var response = xhr.responseText;
            var data = JSON.parse(response);
            if (data && data.errno == 20001) {
                cc.director.popToRootScene();
            }
            // 需要登陆
            if(callback) {
                callback(null, JSON.parse(response));
            }
        }else if(xhr.readyState == 4 && xhr.status != 200){
            var response = xhr.responseText;
            if(errorcallback)
                errorcallback(null, JSON.parse(response));
        }
    };


```

每次执行到 cc.director.popToRootScene();  都黑屏