JQuery Ajax过程AOP:用于在Ajax请求发送过程中执行必备操作,比如加载数据访问令牌。
$.ajaxSetup({ type: "POST", error: function(jqXHR, textStatus, errorThrown){ switch (jqXHR.status) { case(500): alert("服务器系统内部错误"); break; case(401): alert("未登录"); break; case(403): alert("无权限执行此操作"); break; case(408): alert("请求超时"); break; default: alert("未知错误"); } }, success: function(data) { }, statusCode:{ 200 : function() { } }, beforeSend: function(jqXHR) { var ex_cnn = getCookie("ex_cnn"); var ex_cnv = getCookie("ex_cvn"); if(ex_cnn == null || ex_cnn == "" || ex_cnv == null || ex_cnv == ""){ } var ex_cvn = getCookie(ex_cnn); var ex_cvv = getCookie(ex_cnv); jqXHR.setRequestHeader("platform", ex_cvn); jqXHR.setRequestHeader("mstoken", ex_cvv); var msinit_validtype = getCookie("msinit_validtype"); var msinit_validvalue = ""; if(msinit_validtype == "oa"){ msinit_validvalue = getCookie("oa_token"); } else if(msinit_validtype == "fp"){ msinit_validvalue = getCookie("sfut"); } jqXHR.setRequestHeader("validatetype", msinit_validtype); jqXHR.setRequestHeader("validatevalue", msinit_validvalue); } });