javascript 获取SharePoint 2010/2013 userID

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 获取SharePoint 2010/2013 userID相关的知识,希望对你有一定的参考价值。

//
// Include JQuery reference
// ... script continues ...


 // 0#.w|domain\user

        /// username should be passed as 'domain\username'
        function GetUserId(userName) {
            /// change this prefix according to the environment.
            /// In below sample, windows authentication is considered.
            var prefix = "VIC\\";
            /// get the site url
            var siteUrl = _spPageContextInfo.siteAbsoluteUrl;
            /// add prefix, this needs to be changed based on scenario
            var accountName = prefix + userName;
            /// set domain Name

            /// make an ajax call to get the site user
            $.ajax({
                url: siteUrl + "/_api/web/siteusers(@v)?@v='" +
                    encodeURIComponent(accountName) + "'",
                method: "GET",
                headers: { "Accept": "application/json; odata=verbose" },
                success: function (data) {
                    ///popup user id received from site users.
                    alert("Received UserId" + data.d.Id);
                    alert(JSON.stringify(data));
                },
                error: function (data) {
                    console.log(JSON.stringify(data));
                }
            });
        }

以上是关于javascript 获取SharePoint 2010/2013 userID的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript sharepoint:使用Javascript从任何页面获取顶级Style-Library网址

使用带有Sharepoint的javascript按标题查找元素

sharepoint JQ获取List列表的值

如何在 sharepoint 2013 中获取 oauth 访问令牌?

无法在Sharepoint 2013在线自定义列表中使用SPD获取Lookup字段值

Sharepoint PeopleEditor操作