03-http.js 1.9 KB
!function(e,t){e.gxb={},e.gxb._={},e.gxb.http=e.gxb._.http={resloveUrl:function(e){return e},GetQueryString:function(e){var t=new RegExp("(^|&)"+e+"=([^&]*)(&|$)"),n=window.location.search.substr(1).match(t);return null!=n?unescape(n[2]):null}},e.gxb._.ajaxs={_:{},push:function(t,n){e.gxb._.ajaxs._[t]=n},pop:function(t){e.gxb._.ajaxs._[t]=null},get:function(t){return e.gxb._.ajaxs._[t]}},e.gxb._.ajax=function(n,a){"object"==typeof n&&(a=n,n=null);var s={url:n||a.url||"",type:"get",dateType:"html",data:{}};for(a=t.extend(s,a),n=a.url;"/"==n[0]||" "==n[0];)n=n.substring(1,n.length);if(0==n.length)return e.console.log("无效的请求地址"),null;var r=n.toLowerCase();if(r.indexOf(".js")<0&&r.indexOf(".css")<0){var o=r.indexOf("?");o>0?n=n.substring(0,o)+"/api"+n.substring(o)+"&"+(new Date).getTime():n+="/api?"+(new Date).getTime()}var u=function(){var t;do t=Math.random()+"00000000",t=t.substr(t.indexOf(".")+1,6);while(e.gxb._seq[t]);return e.gxb._seq[t]=!0,t},c={url:e.gxb._.http.resloveUrl(n),data:a.data||{},dateType:a.dateType||"html",contentType:"undefined"!=typeof a.contentType&&null!=a.contentType?a.contentType:"application/x-www-form-urlencoded;charset=utf-8",type:a.type||"get",processData:"undefined"==typeof a.processData||null==a.processData||a.processData,cache:"undefined"==typeof a.cache||null==a.cache||a.cache,complete:function(t){var n=a.complete;"function"==typeof n&&n(t),e.gxb._.ajaxs.pop(u)},success:function(e){var t=a.success;"function"==typeof t&&t(e)},error:function(e){var t=a.error,n=function(){if(e&&500==e.status){try{var t=gxb.utils.toJsonObj(e.responseText)}catch(e){var t={}}return{status:!1,message:t.message||"发生未知异常!",type:t.type}}return 403==e.status?{status:!1,message:"您没有访问权限!"}:{status:!1,message:"发生未知异常!"}};if("function"==typeof t)t(n(e));else{var s=n(e);console.log(s.message)}}},i=t.ajax(c);return{abort:function(){i.abort()}}}}(window,jQuery);