Display Login User Display name and Email Address Using REST API(SharePoint 2013)
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"> </script>
<script type="text/javascript" src="/_layouts/15/sp.js">
</script>
<div>
<input type="button" value="Display Ddata" onclick="getLoggedUserName();" />
</div>
<script type="text/javascript">
function getLoggedUserName()
{
var userid = _spPageContextInfo.userId;
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/getuserbyid(" + userid + ")";
var requestHeaders = { "accept": "application/json;odata=verbose" };
$.ajax({
url: requestUri,
contentType: "application/json;odata=verbose",
headers: requestHeaders,
success: onSuccess,
error: onError
});
function onSuccess(data, request) {
var Logg = data.d;
//get
login name
var loginName = Logg.LoginName.split('|')[1];
// var
emailId = Logg.Email
alert(loginName);
//get
display name
alert(Logg.Title);
alert(Logg.Email);
}
function onError(error) {
alert("error");
}
}
</script>
No comments:
Post a Comment