使用GetListItems与SharePoint 2010中的Ajax调用

时间:2017-07-05 13:51:54

标签: jquery ajax web-services sharepoint sharepoint-2010

我尝试使用Lists.asmx编写ajax调用来从SharePoint检索列表项

即使我正确地处理格式化,我仍然会收到302错误。我错过了什么吗?

代码

function makeSoapCall(listName){
    var soapEnv =  
    "<?xml version='1.0' encoding='utf-8'?> " +
    "<soap12:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap12='http://www.w3.org/2003/05/soap-envelope'> " +
        "<soap12:Body> " +
            "<GetList xmlns='http://schemas.microsoft.com/sharepoint/soap/'> " +
                "<listName>Webpostings Approvers</listName> " +
            "</GetList> " +
        "</soap12:Body> " +
    "</soap12:Envelope>";

        $.ajax({
            url: "http://webpub.ex.com/_vti_bin/Lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            contentType: "application/soap+xml; charset=utf-8"
        });
    }

响应

http://webpub.ex.com/_layouts/error.aspx?ErrorText=Request format is unrecognized.

1 个答案:

答案 0 :(得分:0)

因为您需要列表项。您必须使用Getlistitems而不是Getlist。

 function getSharepointListData (myList) {

       var listName = myList;

    var soapEnv =
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
            <soapenv:Body> \
                 <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                    <listName>"+listName+"</listName> \
                    <viewFields> \
                        <ViewFields> \
                           <FieldRef Name='Author' /> \
                       </ViewFields> \
                    </viewFields> \
                </GetListItems> \
            </soapenv:Body> \
        </soapenv:Envelope>";

    $.ajax({
        url: "http:URL/_vti_bin/lists.asmx",
        type: "POST",
        dataType: "xml",
        data: soapEnv,
        complete: processResult,
        contentType: "text/xml; charset=\"utf-8\""
    });