jquery
  • sharepoint
  • cross-domain
  • 2012-03-05 84 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

    相关问题