-1

xhrFields: jquery - ajax呼び出しでif条件を追加することは可能ですか?

元:

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

2 に答える 2

1

試す:

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

ただし、!='Y'のときにオプションを完全に省略する必要がある場合はflag、次のようにすることができます。

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 に答える