jquery
  • sharepoint
  • cross-domain
  • 2012-03-05 86 views 2 likes 
    2

    我想從訪問列表數據neighbor.domain.com使用Javascript on home.domain.com。兩者都是Sharepoint 2007.跨子域Sharepoint列表訪問

    我使用的代碼來自this question's top answer

    $(function(){ 
        var soapEnv = 
        "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \ 
         <soapenv:Body> \ 
          <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \ 
           <listName>Documents</listName> \ 
           <viewFields> \ 
            <ViewFields> \ 
             <FieldRef Name='Title' /> \ 
            </ViewFields> \ 
           </viewFields> \ 
          </GetListItems> \ 
         </soapenv:Body> \ 
        </soapenv:Envelope>"; 
        $.ajax({ 
         url: "http://neighbor.domain.com/sites/site1/_vti_bin/lists.asmx", 
         type: "POST", 
         dataType: "xml", 
         data: soapEnv, 
         contentType: "text/xml; charset=\"utf-8\"", 
         complete: function(xData, status){ 
          $(xData.responseXML).find("z\\:row").each(function(){ 
           var title = $(this).attr("ows_FileLeafRef").split("#")[1]; 
           alert(title); 
          }) 
         }, 
         error: function(){ 
          alert("error"); 
         } 
        }); 
    }); 
    

    它對我不起作用。我收到一個錯誤:訪問被拒絕
    我已經加入jQuery.support.cors = true,但沒有運氣。

    有什麼我失蹤了嗎?是否需要在其他域實現某些功能(neighbor.domain.com)?

    我沒有對服務器計算機的管理訪問權限(只有開發人員才能訪問Sharepoint)。我只有讀訪問neighbor.domain.com

    UPDATE(2013年7月10日):我比讀訪問權neighbor.domain.com更多。我的解決方案涉及在另一個子域上添加一個文件,該文件將根據傳遞給它的URL參數來檢索列表數據。

    +0

    你也許得到與NT驗證的雙躍點問題? – Nat 2012-03-05 21:11:12

    +0

    有什麼方法可以測試嗎?直到今天,我還沒有聽說過雙跳問題。基於[本文](http://weblogs.asp.net/owscott/archive/2008/08/22/iis-windows-authentication-and-the-double-hop-issue.aspx):我知道匿名訪問被禁用,不確定模擬。 – branflake 2012-03-05 21:21:17

    +0

    您可以通過硬編碼ajax調用的憑據來進行測試。 – Nat 2012-03-05 21:31:34

    回答

    0

    我的最終解決方案包括增加是充當代理檢索數據上neighbor.domain.com,使用Javascript文件。

    腳本上neighbor.domain.com

    document.domain = 'domain.com'; // Important, so that both pages are considered 
               // the same domain. Allows us to access the 
               // parent object when this page is loaded in an 
               // iframe on the same domain. 
    
    // Returns value of URL parameter 
    function getURLParameter(name) { ... }  
    
    // Retrieves URL parameters that tell the proxy what to do 
    // The Web services operation to call 
    var operation = getURLParameter("operation"); 
    // The URL path of the site (i.e. /sites/sitename) 
    var weburl = getURLParameter("weburl"); 
    // The name of the list on the site 
    var listname = getURLParameter("listname"); 
    
    // Run the requested web service operation 
    if (operation === "GetListItems") { 
        $().SPServices({ 
        operation: operation, 
        listName: listname, 
        webURL: weburl, 
        completefunc: function (xData, Status) { 
         // parent is a defined object when this page is loaded in an iframe on the 
         // same domain. The parent must have a 'passListItemsData' function 
         // defined. 
         parent.passListItemsData(xData.responseXML); 
        } 
        }); 
    } 
    // Add more operations (and recognized URL params) as needed 
    else if (...) {...} 
    

    home.domain.com調用腳本:

    document.domain = 'domain.com'; // Important, so that both pages are considered 
               // the same domain. Allows the proxy page to 
               // access functions defined on this page. 
    
    // Create an iframe that makes a request of the proxy file using URL parameters 
    var iframe = document.createElement("iframe"); 
    iframe.style.display = "none"; 
    iframe.src = "neighbor.domain.com/path/proxyfile.html?operation=GetListItems&" + 
          "weburl=/sitepath/sitename&listname=name"; 
    document.body.appendChild(iframe); // Requests proxy page and kicks off the 
                // process 
    
    /** 
    * Implements the passListItemsData function for the subdomain proxy. This 
    * handles the results of a GetListItems function on the other subdomain. 
    * @param data, results returned by the GetListItems Lists web service function 
    */ 
    function passListItemsData(data) { 
        // Handle returned XML data from GetListItems web service 
    } 
    
    0

    試試我對這個問題的回答。這是比較容易:)這是here

    +0

    在我沒有對實際服務器計算機的管理訪問權限的情況下工作嗎? – branflake 2012-03-06 15:14:37

    +0

    如果遵循編碼最佳實踐 - 沒有。但是,如果你能應付骯髒的解決方案而不是。您可以創建一個帶有Web部件的沙箱解決方案,並將其放置在同一個域中的某個頁面上。那麼你在js中請求這個頁面(這個頁面可能與你的腳本運行在同一頁面)並且有一個特殊的請求(例如查詢字符串中的一個參數),並且在處理請求webpart期間看到這是你特殊類型的請求並連接到您的其他域,然後呈現輸出。那麼你解析ajax請求的結果並獲得結果。 – 2012-03-06 15:39:31

    +0

    那麼你在說什麼:使用C#創建一個自定義Web部件,它將根據URL查詢字符串參數從另一個域請求信息? – branflake 2012-03-06 19:23:20

    相關問題