I have a function with an if statement which contains two separate AJAX call operations. Based on a variable called subjectType, the conditions for the call change. If I'm trying to get user information I need to give it the userLoginName. If I'm trying to get Site information I need to give it the webURL.
I can accomplish this using an if statement but is there a better way to do this without having to repeat most of the lines?
var subjectType = if(/*I'll check the value of the drop down to see if a user or site report was asked for*/)?"GetGroupCollectionFromUser":"GetGroupCollectionFromWeb";
function parseSubjectColFromUser(subject){
var subjectGroups = [];
if (subjectType){
$().SPServices({
operation: "GetGroupCollectionFromUser",
userLoginName: subject,
completefunc: function(xData, Status){
$(xData.responseXML).find("Group").each(function(){
subjectGroups.push($(this).attr('Name'));
});
}
});
}else{
$().SPServices({
operation: "GetGroupCollectionFromWeb",
webURL: subject,
completefunc: function(xData, Status){
$(xData.responseXML).find("Group").each(function(){
subjectGroups.push($(this).attr('Name'));
});
}
});
}
return subjectGroups;
}
$().SPServices({...into a function and put invocations in both conditional branches?