-1

是否可以在 xhrFields 中添加 if 条件:在 jquery - ajax 调用中?

前任:

xhrFields : { 
   if(flag =='Y'){
   withCredentials: true 
   }
 }
4

2 回答 2

1

尝试:

xhrFields: {
    withCredentials: flag == 'Y'
}

但是,如果你真的需要在flag!= 'Y' 时完全省略该选项,你可以这样做:

xhrFieldsObj = {
   /* You can put all the static options in here */
};
if (flag == 'Y') {
    xhrFieldsObj.withCredentials = true;
};
...
   xhrFields: xhrFieldsObj
于 2012-10-25T08:48:51.507 回答
1
var xhrFields = {};

if (flag == 'Y') {
    xhrFields.withCredentials = true;
}
于 2012-10-25T08:49:31.840 回答