是否可以在 xhrFields 中添加 if 条件:在 jquery - ajax 调用中?
前任:
xhrFields : {
if(flag =='Y'){
withCredentials: true
}
}
是否可以在 xhrFields 中添加 if 条件:在 jquery - ajax 调用中?
前任:
xhrFields : {
if(flag =='Y'){
withCredentials: true
}
}
尝试:
xhrFields: {
withCredentials: flag == 'Y'
}
但是,如果你真的需要在flag
!= 'Y' 时完全省略该选项,你可以这样做:
xhrFieldsObj = {
/* You can put all the static options in here */
};
if (flag == 'Y') {
xhrFieldsObj.withCredentials = true;
};
...
xhrFields: xhrFieldsObj
var xhrFields = {};
if (flag == 'Y') {
xhrFields.withCredentials = true;
}