JQuery Ajax過程AOP:用於在Ajax請求發送過程當中執行必備操做,好比加載數據訪問令牌。javascript
$.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); } });