$(function () { //继承jquery的$.ajax方法 var _ajax = $.ajax; $.r_ajax = function (opt) { //备份opt中error和complete方法 var fn = {} if (opt.loading) { fn.beforeSend = ajaxLoading(); } if (opt.url.indexOf('?') > -1) opt.url = opt.url + "&ajaxGuid=" + GetGuid(); else opt.url = opt.url + "?ajaxGuid=" + GetGuid(); try { let nowurl = window.location.href let p = nowurl.split('?')[1] if (p) { let keyValue = p.split('&'); let obj = {}; for (let i = 0; i < keyValue.length; i++) { let item = keyValue[i].split('='); let key = item[0]; let value = item[1]; obj[key] = value; } console.log(obj); if (obj["mytoken"]) { opt.url = opt.url + "&mytoken=" + obj["mytoken"]; } console.log(opt); } } catch (e) { } fn.complete = opt.complete; //扩展增强处理 var _opt = $.extend(opt, { complete: function (xhr, ts) { //成功回调方法增强处理 if (opt.loading) ajaxLoadEnd(); if (fn.complete != null) fn.complete(xhr, ts); } }); _ajax(_opt); }; $.r_ajax_ev = function (opt) { //备份opt中error和complete方法 var fn = {} if (opt.loading) { fn.beforeSend = ForEverajaxLoading(); } if (opt.url.indexOf('?') > -1) opt.url = opt.url + "&ajaxGuid=" + GetGuid(); else opt.url = opt.url + "?ajaxGuid=" + GetGuid(); fn.complete = opt.complete; //扩展增强处理 var _opt = $.extend(opt, { complete: function (xhr, ts) { //成功回调方法增强处理 if (opt.loading) ForEverajaxLoadEnd(); if (fn.complete != null) fn.complete(xhr, ts); } }); _ajax(_opt); }; //继承jquery的$.post方法 var _post = $.post; $.r_post = function (url, data, success, dataType) { ajaxLoading();//Loading功能 var n_success = success; var r_data = data; var r_dataType = dataType || "json"; if (!isJson(data)) { n_success = data; r_data = {}; r_dataType = success; } var r_success = function (r_data, r_textStatus, r_jqXHR) { ajaxLoadEnd(); n_success(r_data, r_textStatus, r_jqXHR); } if (url.indexOf('?') > -1) url = url + "&postGuid=" + GetGuid(); else url = url + "?postGuid=" + GetGuid(); try { let nowurl = window.location.href let p = nowurl.split('?')[1] if (p) { let keyValue = p.split('&'); let obj = {}; for (let i = 0; i < keyValue.length; i++) { let item = keyValue[i].split('='); let key = item[0]; let value = item[1]; obj[key] = value; } console.log(obj); if (obj["mytoken"]) { r_data.data.mytoken = obj["mytoken"]; } console.log(r_data); } } catch (e) { } _post(url, r_data, r_success, r_dataType); }; $.r_post_ev = function (url, data, success, dataType) { ForEverajaxLoading();//Loading功能 var n_success = success; var r_data = data; var r_dataType = dataType || "json"; if (!isJson(data)) { n_success = data; r_data = {}; r_dataType = success; } var r_success = function (r_data, r_textStatus, r_jqXHR) { ForEverajaxLoadEnd(); n_success(r_data, r_textStatus, r_jqXHR); } if (url.indexOf('?') > -1) url = url + "&postGuid=" + GetGuid(); else url = url + "?postGuid=" + GetGuid(); _post(url, r_data, r_success, r_dataType); }; }) //判断是否为json function isJson(obj) { var isjson = typeof (obj) == "object" && Object.prototype.toString.call(obj).toLowerCase() == "[object object]" && !obj.length; return isjson; } var timeid = null; function ajaxLoading() { $("
").css({ display: "block", width: "100%", height: $(window).height(), "z-index": "29991015" }).appendTo("body"); $("
").html("正在处理,请稍候。。。").appendTo("body").css({ display: "block", "z-index": "29991015", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 }); //timeid = window.setInterval(ajaxLoadEnd, "30000");//30s后无响应自动关闭 } function ajaxLoadEnd() { try { var mask = $(".datagrid-mask"); if (mask != null) { $(mask).remove(); } var maskmsg = $(".datagrid-mask-msg"); if (maskmsg != null) { $(maskmsg).remove(); } if (timeid != null) window.clearInterval(timeid); timeid = null; } catch (e) { } } function ForEverajaxLoading() { $("
").css({ display: "block", width: "100%", height: $(window).height() }).appendTo("body"); $("
").html("正在处理,请稍候。。。").appendTo("body").css({ display: "block", left: ($(document.body).outerWidth(true) - 190) / 2, top: ($(window).height() - 45) / 2 }); } function ForEverajaxLoadEnd() { try { var mask = $(".datagrid-mask"); if (mask != null) { $(mask).remove(); } var maskmsg = $(".datagrid-mask-msg"); if (maskmsg != null) { $(maskmsg).remove(); } } catch (e) { } } //检测当前浏览器类型 function explorerType() { var ieType; if ((navigator.userAgent.indexOf('MSIE') >= 0) && (navigator.userAgent.indexOf('Opera') < 0)) { ieType = "ie"; } else if (navigator.userAgent.indexOf('Firefox') >= 0) { ieType = "firefox"; } else if (navigator.userAgent.indexOf('Opera') >= 0) { ieType = "opera"; } else if (navigator.userAgent.indexOf('Chrome') >= 0) { ieType = "chrome"; } else if (navigator.userAgent.indexOf('version') >= 0) { ieType = "safari"; } else { ieType = "other"; } return ieType; } function GetGuid() { var s4 = function () { return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1); }; return s4() + s4() + s4() + "-" + s4(); }