2017-07-05 80 views
0

Ajax調用使用GetListItems我試圖寫一個ajax呼叫從SharePoint檢索列表項使用Lists.asmx與從SharePoint 2010

我不斷收到即使我正確folling格式化一個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. 

回答

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