I'm trying these two ways to get the user id.
$(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(loadUser, "sp.js"); });
function loadUser() {
var ctx = new SP.ClientContext.get_current();
this.web = ctx.get_web();
this.currentUser = this.web.get_currentUser();
ctx.load(this.web);
ctx.executeQueryAsync(Function.createDelegate(this, this.asdasd), Function.createDelegate(this, this.qweqwe));
}
function asdasd(sender, args) {
console.log(this.currentUser.get_id());
}
function qweqwe(sender, args) {
console.log(args.get_message());
}
And replacing the top line with this.
$(document).ready(function () {
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', loadUser);
});
Sometimes it brings the id and sometimes not, can someone help me to make this work constantly?