I'm trying to get the group of current user. By using this code:
function checkGroup() {
var group = ["D", "Sup", "A", "CP"];
for (var i = 0; i < group.length; i++) {
if (isMember(group[i]) == true)
{
alert('I am a member of the group'+ i);
break;
}
}
}
function isMember(groupName){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('"+groupName+"')/Users?$filter=Id eq " + _spPageContextInfo.userId,
method: "GET",
headers: { "Accept": "application/json; odata=verbose"},
success: function (data) {
alert('I am a member of the group' + groupName);
return true;
},
error: function (data) {
return false;
},
asyn:false,
});
}
the problem is , it always return true , means i the member of all group which is false .
Any idea ??