/*! *mciservices.js *Copyright (c) 2012-2013 * */ /// var mci = {}; ; (function () { //封装ajax请求 var jsonProxy = function (serviceUrl) { this.callGet = function (url,params, suc, err) { /// 封装ajax请求. /// 服务的url [/user/{param2}/{param1}] /// /// ajax请求成功后执行的回调函数. /// ajax请求失败后执行的回调函数. var getUrl = url; var reg = /\{(.*?)\}/ig; var m = getUrl.match(reg); if (m) { m = Array.prototype.slice.call(m) for (var i in m) { getUrl = getUrl.replace(m[i], params[m[i].replace("{", "").replace("}", "")]); } } /* try{ window.insertHtml.vloading(true); }catch(e){ console.log(e); }*/ var ajaxGet = $.ajax({ url: serviceUrl+getUrl, type: 'GET', cache: false, dataType: 'json', error: function (obj) { //ajax request error //console.log("request error", obj); if ($.isFunction(err)) { var result = {}; result.d = obj; err(result); } else { } }, success: function (obj) { //ajax request success if ($.isFunction(suc)) { var result = {}; result.d = obj; if (obj.isSuc == false && obj.message == "未登录") { var host = window.location.host; var arrTemp = host.split("."); arrTemp.splice(0,1); localStorage.setItem("loginSession","过期"); if(host.indexOf("test") > -1){ window.location.href = "http://test."+ arrTemp.join(".") +"/index.html"; }else{ window.location.href = "http://www."+ arrTemp.join(".") +"/index.html"; } } suc(result); } else { //console.log(obj); } }, complete: function(){ /* try{ window.insertHtml.vloading(false); }catch(e){ console.log(e); }*/ } }); return ajaxGet; } this.callPost = function (url, data, suc, err) { /// 封装ajax请求. /// 服务的url /// post data /// ajax请求成功后执行的回调函数. /// ajax请求失败后执行的回调函数. var getUrl = url; var d = JSON.stringify(data); /* try{ window.insertHtml.vloading(true); }catch(e){ console.log(e); }*/ var ajaxPost = $.ajax({ url: serviceUrl + getUrl, type: 'POST', cache: false, data:d, dataType: 'json', contentType: "application/json", error: function (obj) { //ajax request error if ($.isFunction(err)) { var result = {}; result.d = obj; err(result); } else { } }, success: function (obj) { //ajax request success if ($.isFunction(suc)) { var result = {}; result.d = obj; if (obj.isSuc == false && obj.message == "未登录") { var host = window.location.host; var arrTemp = host.split("."); arrTemp.splice(0,1); localStorage.setItem("loginSession","过期"); if(host.indexOf("test") > -1){ window.location.href = "http://test."+ arrTemp.join(".") +"/index.html"; }else{ window.location.href = "http://www."+ arrTemp.join(".") +"/index.html"; } } suc(result); } else { //console.log(obj); } }, complete: function(){ /*try{ window.insertHtml.vloading(false); }catch(e){ console.log(e); }*/ } }); return ajaxPost; } }; /* var host ="http://test.csmen.cc/services";*/ var host ="/services"; mci.host = host; mci.hostservice = new jsonProxy(host+'/'); mci.qiniuservice = new jsonProxy(host + "/qiniu/");//七牛token mci.userservice = new jsonProxy(host + "/user/"); mci.albumservice = new jsonProxy(host + "/album/"); mci.albumpictureservice = new jsonProxy(host + "/albumpicture/"); mci.industservice = new jsonProxy(host + "/tag/"); mci.tagservice = new jsonProxy(host + "/tag/"); mci.modelstyleservice = new jsonProxy(host + "/indexstyle/"); mci.templateservice = new jsonProxy(host + "/template/"); mci.articleresourceservice = new jsonProxy(host + "/articleresource/"); mci.articleservice = new jsonProxy(host + "/article/"); mci.groupservice = new jsonProxy(host + "/group/"); mci.pushmessageservice = new jsonProxy(host + "/pushmessagelog/"); mci.albumresourceservice = new jsonProxy(host + "/albumresource/"); mci.channelservice = new jsonProxy(host + "/channel/"); mci.custommenuservice = new jsonProxy(host + "/custommenu/"); mci.templateservice = new jsonProxy(host + "/template/"); mci.statservice = new jsonProxy(host + "/stat/"); mci.goodsservice = new jsonProxy(host + "/goods/"); mci.goodstypeservice = new jsonProxy(host + "/goodstype/"); mci.activityservice = new jsonProxy(host + "/activity/"); mci.recactivityservice = new jsonProxy(host + "/recactivity/"); mci.recinfoservice = new jsonProxy(host + "/recinfo/"); mci.recgoodstypeservice = new jsonProxy(host + "/recgoodstype/"); mci.userextentservice = new jsonProxy(host + "/userextent/"); mci.userroleservice = new jsonProxy(host + "/userrole/"); mci.productpriceservice = new jsonProxy(host + "/productprice/"); mci.proxyandroidapk = new jsonProxy("/api/appversion/"); var hostTuwen = "http://www.tuwen.la/api"; mci.tuwen2articleservice = new jsonProxy(hostTuwen + "/article/"); mci.list4md2templateservice = new jsonProxy(hostTuwen + "/template/"); mci.dataCallBack = function(Json) { var result = Json.data, callBack = Json.callBack, error = Json.error; if(result.isSuc) return callBack === undefined ? false : callBack(result); else error === undefined ? insertHtml.error(true,result.message,4,"确定") : error; }; })();