2012-08-24 46 views

回答

1

谷歌 「之外的SharePoint spservices」。

第二個鏈接是Must the page using SPServices be hosted within SharePoint?

從SPServices作者:

儘管在您使用SPServices的頁面並不是 的SharePoint中,它的共同碰上如果身份驗證問題他們不是 。 SharePoint不知道用戶的身份,或者可能存在跨域腳本問題。 有太多的變化,我通常會給出一個是或否的答案。

1

這是一個古老的線程,但經過多少痛苦嘗試此我自己,我通過創建自身加載託管SharePoint網站上的另一個HTML頁面獨立的html頁面的iframe周圍認證困境了。加載在iFrame中的頁面使用postMessage()將List數據發送到父頁面。這似乎也適用於Firefox和Chrome。

總結:

第1步:創建一個html頁面(SharepointProxy.html),並把這個網站上的SharePoint列表要查詢:

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Web Proxy IFrame</title> 
     <meta charset="windows-1252"> 
     <meta name="viewport" content="width=device-width"> 
     <script src="jquery-1.10.2.js"></script> 
     <script src="jquery.SPServices-2014.01.js"></script> 
     <script> 
      function callback(e){ 

       if(e.origin == "https://your.otherdomain.com/index"){ //this is your standalone web page 
        e.source.postMessage(jsonToSend, "https://your.otherdomain.com/index"); //same standalone web page here 
       } 
       return true; 
      } 
     </script> 
    </head> 
    <body> 
     <h1>SharePoint proxy - Do Not delete!</h1> 
     <p>If you'd like to know further detail about its purpose, please email [email protected]</p> 
     <h2>Purpose</h2> 
     <p>This page serves as a proxy to call within an Iframe on an external site. This page fetches [whatever] 
      from the SharePoint Portal and makes them available as a JSON string</p> 


     <script> 
      var someListData; 
      $().SPServices({ 
       operation: "GetListItems", 
       webURL: "https://sharepoint-portal.com/sites/your_site", 
       listName: "List Name", 
       async: false, 
       completefunc: function(xData, Status) { 
        //alert(xData.responseText); 
        someListData = $(xData.responseXML).find("z\\:row, row").map(function() { 
         return { 
          value: $(this).attr("ows_LinkTitle") || " ", 
          desc: $(this).attr("ows_Details") || " " 
         }; 
        }).get(); 
       } 
      }); 

      var jsonToSend = JSON.stringify(someListData); 

      document.addEventListener("message", callback,false); 
      window.top.postMessage(jsonToSend, "*"); 
     </script> 
    </body> 
</html> 

步驟2:在您要在哪裏顯示您的Sharepoint列表數據,請將這些函數用於創建iFrame並從SharePoint加載您的頁面:

(function() { //create an iFrame to load our SharepointProxy.html page inside of 
    var iFrame = document.createElement("iframe"); 
    iFrame.style.display = "none"; 
    iFrame.id = "sharePointProxyFrameContainer"; 
    iFrame.src = "https://sharepoint-portal.com/sites/your_site/Site%20Assets/SharepointProxy.html"; 
    document.body.appendChild(iFrame); 
})(); 

function processSharePointListData(d){ 
    var data = JSON.parse(d); 
    // do something with data 
} 

window.addEventListener("message", function(e) { 
    if (e.origin === "https://sharepoint-portal.com/") { 
     processSharePointListData(e.data); 
     return true; 
    } 

}, false); 
相關問題