您的位置:首页 > 理论基础 > 计算机网络

cocosjs使用http请求

2015-11-03 10:01 711 查看
var httpHelper = {};
httpHelper.get = function(url, callback){
var xhr = cc.loader.getXMLHttpRequest();
console.log("Status: Send Get Request to ", url);
xhr.open("GET", url, true);

xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
var httpStatus = xhr.statusText;
var response = xhr.responseText;
console.log("Status: Got GET response! " + httpStatus);
callback(true, xhr);
}else{
callback(false, xhr);
}
};
xhr.send();
};


使用时

var url = "xxxxxx";
httpHelper.get(url,function(isSuccess, data){});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  cocosjs