【问题标题】:Call SPService from outside SharePoint page context从外部 SharePoint 页面上下文调用 SPService
【发布时间】:2017-08-03 11:05:34
【问题描述】:

使用来自 codeplex 的 SPServices jQuery 库或任何其他基于 javascript 的解决方案是否可以使用此库和 jQuery 从独立的 HTML 页面调用 SharePoint 2010 Web 服务?基本上我需要将文件上传到现有的文档集,但我需要从独立页面这样做。用户将处于单点登录状态并登录到 Dynamics CRM。

SPService at CodePlex

【问题讨论】:

    标签: jquery sharepoint-2010


    【解决方案1】:

    Google“共享点外的 spservices”。

    第二个链接是Must the page using SPServices be hosted within SharePoint?

    来自 SPServices 作者:

    虽然您使用 SPServices 的页面没有在其中 SharePoint,如果遇到身份验证问题,则很常见 不是。 SharePoint 不知道用户的身份,或者可以 算是跨域脚本问题。有太多的变化 所有这一切让我通常给出是或否的答案。

    【讨论】:

      【解决方案2】:

      这是一个旧线程,但在我自己尝试了很多痛苦之后,我通过在一个独立的 html 页面上创建一个 iFrame 来解决身份验证问题,该页面本身会加载另一个托管在 SharePoint 网站上的 html 页面。 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 someperson@some.com</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);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-31
        相关资源
        最近更新 更多