深入浅出SharePoint——利用jQuery访问SharePoint Web Service获取用户信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | function document.onkeyup() { if (window.event.keyCode == 9) { var fldAD = $(document).find( ".ms-formtable" ).children().find( "input[title='Title']" )[0].value; if (fldAD != "" ) { GetUserProfileByName(fldAD); } } } $(document).ready( function () { }); function GetUserProfileByName(accountName) { //Administrator //Build the URL of the Lists.asmx web service. //This is done by stripping the last two parts (/doclib/page) of the URL. var hrefParts = window.location.href.split( '/' ); var wsURL = hrefParts[0] + "/_vti_bin/UserProfileService.asmx" ; //URL:http://Minda/_vti_bin/UserProfileService.asmx //The SOAP Envelope to send to the Lists.asmx web service. //Tip: this XML can be copied from /_vti_bin/lists.asmx?op=GetListCollection var soapEnv = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>" + "<soapenv:Body>" + "<GetUserProfileByName xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'>" + "<AccountName>" + accountName + "</AccountName>" + "</GetUserProfileByName>" + "</soapenv:Body>" + "</soapenv:Envelope>" ; //Do the web service call async. $.ajax({ url: wsURL, type: "POST" , dataType: "xml" , data: soapEnv, complete: processResult, contentType: "text/xml; charset=\"utf-8\"" }); } function processResult(xData, status) { var properties = $(xData.responseXML).find( "PropertyData" ); $(properties).filter( function () { return "FirstName" == $( this ).find( "Name" ).text(); }).each( function () { $(document).find( ".ms-formtable" ).children().find( "input[title='CostCenter']" )[0].value = $( this ).find( "Value" ).text(); }); } |
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步