<script type="text/javascript">
$(document).ready(function () { getCurrentUser(); });
function getCurrentUser() {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/CurrentUser",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
getCurrentUserGroupColl(data.d.Id);
},
error: function (data) {
failure(data);
}
});
}
function getCurrentUserGroupColl(UserID) {
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + UserID + ")/Groups",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
/* get all group's title of current user. */
var results = data.d.results; var InnrHtmlgrp = "<ul>";
for (var i = 0; i < results.length; i++) {
lstgrp += "<li>" + results[i].Title + "</li>";
}
$("#bindGroup").append(lstgrp + "</ul>");
}
});
}
</script>
<div id="bindGroup"></div>
$(document).ready(function () { getCurrentUser(); });
function getCurrentUser() {
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/CurrentUser",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
getCurrentUserGroupColl(data.d.Id);
},
error: function (data) {
failure(data);
}
});
}
function getCurrentUserGroupColl(UserID) {
$.ajax
({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/GetUserById(" + UserID + ")/Groups",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: function (data) {
/* get all group's title of current user. */
var results = data.d.results; var InnrHtmlgrp = "<ul>";
for (var i = 0; i < results.length; i++) {
lstgrp += "<li>" + results[i].Title + "</li>";
}
$("#bindGroup").append(lstgrp + "</ul>");
}
});
}
</script>
<div id="bindGroup"></div>
No comments:
Post a Comment