从外部SharePoint页面上下文调用SPService

时间:2012-08-24 19:37:40

标签: jquery sharepoint-2010

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

SPService at CodePlex

2 个答案:

答案 0 :(得分:1)

Google" sharepoint以外的spservices"。

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

来自SPServices作者:

  

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

答案 1 :(得分:1)

这是一个老线程,但是在经历了很多痛苦的尝试后,我通过在独立的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 List数据的网页上,放置这些功能以创建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);