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){});