使用jquery在sharepoint 2010中获取当前记录的用户名及其ID

m4pnthwp  于 2023-01-01  发布在  jQuery
关注(0)|答案(1)|浏览(131)

我没有得到当前的用户名和ID的这个方法,为什么有什么错误。

$().SPServices({
    operation: "GetUserInfo",
    async: false,
    userLoginName: $().SPServices.SPGetCurrentUser(),
    completefunc: function (xData, Status) {
        $(xData.responseXML).find("User").each(function() {
            curUserId = $(this).attr("ID");
            curUserName = $(this).attr("Name");
            curFullUserName = $(this).attr("ID")+";#"+$(this).attr("Name");
        });
    }
});
alert(curUserId);
yshpjwxd

yshpjwxd1#

var context = null;  
var web = null;  
var currentUser = null;  
function getWebUserData() {
    context = new SP.ClientContext.get_current();
    web = context.get_web();
    currentUser = web.get_currentUser();
    currentUser.retrieve();
    context.load(web);
    context.executeQueryAsync(Function.createDelegate(this, this.onSuccessMethod), Function.createDelegate(this, this.onFailureMethod));
}

function onSuccessMethod(sender, args) {
    var userObject = web.get_currentUser();
    alert('User name:' + userObject.get_title() + '\n Login Name:' + userObject.get_loginName());
}
function onFailureMethod(sender, args) {
    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());
}

相关问题