深入浅出SharePoint——利用jQuery访问SharePoint Web Service获取用户信息

 

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();
        });
}

  

转载于:https://www.cnblogs.com/mingle/archive/2012/08/11/2633823.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值