深入浅出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();
        });
}

  

posted @ 2012-08-11 17:20  风影极光  阅读(447)  评论(0编辑  收藏  举报