CocosCreator的XMLHttpRequest短连接获取相应的Json


前言:基于Cocos原有的XMLHttpRequest获取相应的json。

  //定义接口
  let xhr = new XMLHttpRequest();
  //定义接口获取返回方法
  xhr.onreadystatechange = function () {
            if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
                //解析获取到的文本文件,转化成JSON
                let response = JSON.parse(xhr.responseText);
                //let data = JSON.parse(unescape(response.data));
            }
        };
  //指令、地址
  xhr.open("GET", "url", true);
  //执行连接
  xhr.send();


————————————————
原文链接:https://blog.csdn.net/mlhuanggan/article/details/106757811

猜你喜欢

转载自blog.csdn.net/weixin_42565127/article/details/133990843
今日推荐