Cocos Creator 怎么POST和get

yhlovezx
Sat, 30 Jan 2016 07:22:29 +0000

function sendPostRequest(ServerLink,str,callback,errcall) {
var sendstr=JSON.stringify(str);
var xhr = cc.loader.getXMLHttpRequest();
xhr.open(“POST”, ServerLink);
//xhr.open(“GET”, ServerLink+link+"?"+parm,false);
xhr.setRequestHeader(“Content-Type”,“application/x-www-form-urlencoded”);
xhr.send(sendstr);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status <= 207)) {
var result = JSON.parse(xhr.responseText);
if(result"act"]==“erro”) {
errcall(result"msg"]);
return;
}
callback(result);
}
};
}

阅读整个主题