簡體   English   中英

Sharepoint 2013:我無法訪問主機站點

[英]Sharepoint 2013:I Cannot access host site

Sharepoint 2013:我想遍歷mu sharepoint在線網站上顯示的所有列表。 但是,當我加載主機端並調用executeQueryAsync函數時,它似乎總是在調用faliure函數,即我收到一條“失敗”的警報作為輸出

var context = SP.ClientContext.get_current();
var user = context.get_web().get_currentUser(); 
var hostUrl
var hostContext
var site
(function () {

// This code runs when the DOM is ready and creates a context object    which is 
    // needed to use the SharePoint object model
    $(document).ready(function () {

        $('#Add_List').click(function(event)
        {
        //  alert("in Add_List ")
   hostUrl=decodeURIComponent(getQueryStringParameter("SPHostUrl"));
        alert("host URL:"+hostUrl);

        hostContext=new SP.AppContextSite(context,hostUrl)
        site=hostContext.get_web();
        context.load(site)
        context.executeQueryAsync(success,failure)

    })
  });


})();

function getQueryStringParameter(param)
{
 var params=document.URL.split("?")[1].split("&")
//alert(""+params);
for (var i = 0; i < params.length; i = i + 1) {
     var singleParam = params[i].split("=");
     alert(""+singleParam[i])
     if (singleParam[0] == param) {
         alert("if")
         return singleParam[1];

     }
 }
}
function success()
{
 alert("in success")
} 
function failure()
 {
alert("in failure")
}

您需要跨站點庫ProxyWebRequestExecutorFactory ,並且應用清單必須請求對宿主網站的讀取權限。

對於代碼,您可以通過以下方式使用庫:

context = new SP.ClientContext(appweburl);
factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
context.set_webRequestExecutorFactory(factory);
appContextSite = new SP.AppContextSite(context, hostweburl);

this.web = appContextSite.get_web();
context.load(this.web);

對於請求,您必須在清單中包括此權限

<AppPermissionRequests>
  <AppPermissionRequest 
    Scope="http://sharepoint/" 
    Right="Read" />
</AppPermissionRequests>

您可以在MSDN網站上找到更多信息(以及以上示例)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM