SharePoint 2013 – Get Current User LoginName using JSOM & REST
Reference
http://lixuan0125.wordpress.com/2013/05/10/sharepoint-2013-get-current-user-loginname-using-jsom-rest/#comment-218
Reference
http://lixuan0125.wordpress.com/2013/05/10/sharepoint-2013-get-current-user-loginname-using-jsom-rest/#comment-218
$(document).ready(function () {
var userid = _spPageContextInfo.userId;
function GetCurrentUser() {
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 loginName = data.d.LoginName.split('|')[1];
alert(loginName);
}
function onError(error) {
alert(error);
}
GetCurrentUser();
});
No comments:
Post a Comment