Cocos Creator 怎么POST和get
展开全部
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);
}
};
}
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);
}
};
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询