简体   繁体   中英

How Can I receive the GetListItems from Sharepoint List using SOAP?

I need to get the list items from SharePoint List.

I'm doing that locally. I've tried using this code:

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

Then, I received this message:

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

Can anyone help?

Thanks in advance. Edson Martins

Your datatype property of ajax call object is incorrect. It should be "xml". Also your "contentType" property should have application/xml value instead of json.Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM