前言:基于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