(function($){
var BASE_URL = 'http://120.77.221.25:16850';
var COMMOR = '/commor/';
function _validate(args){
var url = args[0];
var params = args[1];
var success = args[2];
var failed = args[3];
if(!params instanceof Object){
throw('params must be a Object')
}
if((success && !success instanceof Function) || (failed && !failed instanceof Function)){
throw('callback must be a Function')
}
}
function _callback(success,failed){
return function(res){
var errcode = res.errcode;
var data = res.data;
var errinfo = res.errinfo;
if(errcode === 0){
success && success(data)
}else{
failed && failed(errcode,errinfo,data)
}
}
}
function httpGet(url,params,success,failed){
_validate(arguments);
$.get(url,params,_callback(success,failed),'json')
}
function httpPost(url,params,success,failed){
_validate(arguments);
$.post(url,params,_callback(success,failed),'json')
}
var commor = {
sessionid:function(params,success,failed){
httpGet(BASE_URL + COMMOR +'sessionid',params,success,failed)
},
peerid:function(params,success,failed){
httpPost(BASE_URL + COMMOR +'sessionid',params,success,failed)
}
}
return window.api = {
commor:commor
}
})(jQuery)
// 调用时
window.api.commor.sessionid({},function(data){
},function(errcode,errinfo,data){
})