如何使用SOAP从Sharepoint List接收GetListItems?

时间:2014-04-03 15:31:12

标签: javascript sharepoint soap

我需要从SharePoint列表中获取列表项。

我在当地这样做。我尝试过使用这段代码:

<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>

    $(document).ready(function() {
        var listName = "Backlog";
        makeSoapCall(listName);
    });

function makeSoapCall(listName){
    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>" + listName + "</listName> \
          <viewName></viewName> \
          <query></query> \
          <viewFields></viewFields> \
          <rowLimit></rowLimit> \
          <queryOptions></queryOptions> \
          <webID></webID> \
        </GetListItems> \
      </soap:Body> \
    </soap:Envelope>"

  $.ajax({
    url: "http://server/site/_vti_bin/Lists.asmx",
    type: "POST",
    dataType: "jsonp",
    data: soapEnv,
    complete: resultsFeedback,
    contentType: "application/json; charset=\"utf-8\""
  });

}

function resultsFeedback(xData, status) {
    console.log("xData: " + xData);
    console.log("status: " + status);
}

然后,我收到了这条消息:

Resource interpreted as Script but transferred with MIME type text/html: "http://server/site/_vti_bin/Lists.asmx?callback=jQuery11100353987290…stItems%3E%20%20%20%3C/soap:Body%3E%20%3C/soap:Envelope%3E&_=1396538736189". jquery-1.11.0.min.js:4 Uncaught SyntaxError: Unexpected token < Lists.asmx:3

xData: [object Object] report.html:37
status: parsererror

有人可以帮忙吗?

提前致谢。 埃德森马丁斯

1 个答案:

答案 0 :(得分:0)

ajax调用对象的数据类型属性不正确。它应该是&#34; xml&#34;。你的&#34; contentType&#34; property应该有application / xml值而不是json。试试这个:

$.ajax({
    url: "http://server/site/_vti_bin/Lists.asmx",
    type: "POST",
    dataType: "xml",
    data: soapEnv,
    complete: resultsFeedback,
    contentType: "application/xml; charset=\"utf-8\""
  });