Get Current Login User Details using Rest API in SharePoint 2013
//Below code will get the current user id from the Site
var currentUserID = _spPageContextInfo.userId;
//this function get the user details from current user id
$(document).ready(function()
{
var success = getUser(currentUserID);
alert(success );
var currentUserID = _spPageContextInfo.userId;
//this function get the user details from current user id
$(document).ready(function()
{
var success = getUser(currentUserID);
alert(success );
});
function getUser(id){
var deferred = $.Deferred();
var serverUrl = _spPageContextInfo.webAbsoluteUrl;
var ListNameUrl = String.format(
"{0}/_api/Web/GetUserById(" + id + ")",serverUrl);
jQuery.ajax({
url: ListNameUrl,
type: "GET",
headers: { "Accept": "application/json;odata=verbose" },
success: function(data) {
var dataResults = data.d;
//get login name
var loginName = dataResults.LoginName.split('|')[1];
alert(loginName);
//get display name
displayName = dataResults.Title;
deferred.resolve();
}
});
return deferred.promise();
}
Comments
Post a Comment