im trying to get user profile picture in my Cilent Web Part but I get a error massage (_spPageContextInfo
is undefined
).
I'm useing REST API
jQuery(document).ready(function () {
GetCurrentUser();
function GetCurrentUser() {
$.ajax({
url: _spPageContextInfo.siteAbsoluteUrl + "/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl",
type: "GET",
headers: {
"accept": "application/json;odata=verbose",
},
success: function (data) {
var userName = data.d.DisplayName;
var picUrl = data.d.PictureUrl;
$('#bild').attr('src', picUrl);
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
});
are there other ways to solve it ? would be appreciated if you could help me solve it
_spPageContextInfo
is directly written on the page via SSOM so you can use it nearly immediately. What do you mean by ClientWebPart? An SP Hosted APP?_spPageContextInfo
is the only suitable object to get thesiteAbsoluteUrl
. If this is not working for you you simply do something wrong.