ajax 初始化请求前携带参数
$(function () {
function SetAjax(wxOpenId, departCode) {
$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function (o) {
if (wxOpenId && departCode) {
o.setRequestHeader('wxOpenId', " " + wxOpenId);
o.setRequestHeader('DepartCode', " " + departCode);
}
}
});
}
var wxOpenId = App.GetQueryStringByName("wxOpenId");
var DepartCode = App.GetQueryStringByName("DepartCode");
if (!wxOpenId) {
wxOpenId = App.GetCookie("wxOpenId");
} else {
App.SetCookie("wxOpenId", wxOpenId, 365);
}
if (!DepartCode) {
DepartCode = App.GetCookie("DepartCode");
} else {
App.SetCookie("DepartCode", DepartCode, 365);
}
if (wxOpenId && departCode){
SetAjax(wxOpenId, departCode);
}
});
function SetAjax(wxOpenId, departCode) {
$.ajaxSetup({
xhrFields: {
withCredentials: true
},
beforeSend: function (o) {
if (wxOpenId && departCode) {
o.setRequestHeader('wxOpenId', " " + wxOpenId);
o.setRequestHeader('DepartCode', " " + departCode);
}
}
});
}
var wxOpenId = App.GetQueryStringByName("wxOpenId");
var DepartCode = App.GetQueryStringByName("DepartCode");
if (!wxOpenId) {
wxOpenId = App.GetCookie("wxOpenId");
} else {
App.SetCookie("wxOpenId", wxOpenId, 365);
}
if (!DepartCode) {
DepartCode = App.GetCookie("DepartCode");
} else {
App.SetCookie("DepartCode", DepartCode, 365);
}
if (wxOpenId && departCode){
SetAjax(wxOpenId, departCode);
}
});
who:whaozl
QQ:1057674944
email:whaozl@163.com
blog:http://www.cnblogs.com/whaozl
note:原创博客请尊重版权,转载必须得到本人同意