jQuery Call web services(SOAP) in SharePoint 2013

本文详细介绍了如何使用jQuery调用SharePoint Web服务中的GetList方法,实现自动化查询SharePoint列表项数量的功能。通过创建自定义列表并添加测试数据,演示了如何构造SOAP封装并获取响应信息,最终利用jQuery选择器解析XML响应,获取所需的数据信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Step by Step Calling web services(SOAP) in SharePoint 2013

As we know sharepoint already provide some sevice for user, we needn't write CAML to query list every time, sharepoint web service have enough methods, it is easy and fast, suggest to call sharepoint serivice.

1. This time, we will analysis the web service using SOAP, and learn how to call the web service in client. here is a web service file:http://servername/_vti_bin/Lists.asmx, and detail:

2. Click a link and show the method in detail, notice the soap envelope.

3. now, we start to coding: we will use the GetList method in this sevice to return the list itmes count with jQuery .

  • a. Create a custom list name hr, and add some data to test.
  • b. The main code is set the soap envelope and get the respond body with posting request. then we can get the detail info in the respond body via F12 in IE. because this is xml file, it support jQuery seletor.

  • c. Here is the code in all:
<script type="text/javascript">
    var isIE = (navigator.appName.toLowerCase().indexOf('netscape') == -1);
    
$(document).ready(function() {
    ExecuteOrDelayUntilScriptLoaded(makeSoapCall, 'sp.js');
});

function makeSoapCall(){
    var soapEnv =
    "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'" +
    " xmlns:xsd='http://www.w3.org/2001/XMLSchema' \
      xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
      <soap:Body> \
        <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
          <listName>" + "hr" + "</listName> \
          <viewName></viewName> \
          <query></query> \
          <viewFields></viewFields> \
          <rowLimit></rowLimit> \
          <queryOptions><QueryOptions xmlns=''><IncludeMandatoryColumns>FALSE</IncludeMandatoryColumns><ViewAttributes Scope='RecursiveAll'/></QueryOptions></queryOptions> \
        </GetListItems> \
      </soap:Body> \
    </soap:Envelope>";
        
        
    $.ajax({
        url:"HTTP://DEV-SP/_vti_bin/Lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });
}

function processResult(xData, status) {
    var result;
    if (isIE)
        result = xData.responseXML
    else
        result = xData.responseText
        
    try {
        if (status == "success" && result){
            $(result).find("rs\\:data").each(function() {
                alert($(this).attr("ItemCount") + " Items found.");
            });
        }
    }
    catch (e) {
        alert(e);
    }
}
 
    
</script>
  • d. Result:

 

Links : Calling the SharePoint 2010 GetListItems web services with Jquery

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值