我通过在Jquery和sharepoint中使用spservice来获取用户信息。 在可视化Web部分中,我已经在Web部件源代码中写过。
<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="User DataUserControl.ascx.cs" Inherits="UserProfileService.User_Data.User_DataUserControl" %>
<script type="text/javascript" src="/sites/AMAC/_layouts/UserProfileService/jquery.SPServices-0.7.2.js" ></script>
<script type="text/javascript" language="javascript">
$(document).ready(function () {
var curUserId;
var curUserName;
var curFullUserName;
$().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");
});
}
});
});
</script>
但我收到错误: 如
'xData'未定义
'jQuery'未定义 请帮助我纠正错误。
答案 0 :(得分:0)
您需要首先加载jQuery,因为SPServices需要它:http://jquery.com/
答案 1 :(得分:0)
> <script
> src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
以上spservices链接 使用SPServices的用户信息