58 lines
1.7 KiB
JavaScript
58 lines
1.7 KiB
JavaScript
// Learn cc.Class:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
|
|
// Learn Attribute:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
|
|
// Learn life-cycle callbacks:
|
|
// - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
|
|
// - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
|
|
|
|
var httpcli = require('httpcli');
|
|
|
|
module.exports = {
|
|
// LIFE-CYCLE CALLBACKS:
|
|
|
|
// onLoad () {},
|
|
|
|
// start () {},
|
|
|
|
// update (dt) {},
|
|
getInstance(){
|
|
if(!this._instance){
|
|
this._instance = new httpcli();
|
|
}
|
|
return this._instance;
|
|
},
|
|
|
|
httpGet(url, cbRes, cbErr){
|
|
// var realurl = url;
|
|
// if(urldata){
|
|
// if(realurl.indexOf("?") == -1){
|
|
// realurl += "?";
|
|
// }else{
|
|
// realurl += "&";
|
|
// }
|
|
// realurl += encodeURIComponent(urldata);
|
|
// }
|
|
return this.httpsend(url, null, cbRes, cbErr, 'GET');
|
|
},
|
|
|
|
httpPost(url, postdata, cbRes, cbErr){
|
|
return this.httpsend(url, postdata, cbRes, cbErr, 'POST');
|
|
},
|
|
|
|
httpsend(url, urldata, cbRes, cbErr, smethod){
|
|
return this.getInstance().httpsend(url, urldata, cbRes, cbErr, smethod);
|
|
},
|
|
|
|
JSON_parse(text){
|
|
try{
|
|
return JSON.parse(text);
|
|
}catch(err){
|
|
console.log(err);
|
|
return null;
|
|
}
|
|
}
|
|
};
|