使用托管站点访问Sharepoint托管应用程序(加载项)中的共享点列表

时间:2020-08-12 14:04:21

标签: jquery sharepoint-online hosted-app project-online

我们创建了一个Sharepoint托管应用程序(加载项),在其中创建了我们需要与托管站点(Project Online租户)一起访问的Sharepoint列表

我们创建了Sharepoint应用程序只是为了保留所有列表和js,我们可以使用托管站点下的页面访问这些列表和js。

在C#代码中,我们能够使用CSOM访问在外接程序中创建的列表,但是当我们尝试使用驻留在托管站点下的jquery文件访问Sharepoint外接程序列表时,这两种方法都将导致REST拒绝访问错误API和共享点上下文。

通过Rest API,我们使用了以下代码

$.ajax({
            url: SharepointAppUrl + "/_api/web/lists/GetByTitle('" + listName + "')/items",
            type: "GET",
            async: true,
            headers: {
                "accept": "application/json;odata=verbose",
                "content-type": "application/json;odata=verbose",
            },
            success: function (data) {
                console.log('list data retrived successfully');
                listdfd.resolve(data);
            },
            error: function (err) {
                alert("Error in fetching list data");
                listdfd.resolve(err);
            }
        });

我们使用上下文尝试如下:

       var clientContext = new SP.ClientContext(SharepointAppUrl);
       var oList = clientContext.get_web().get_lists().getByTitle('Listname');

        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml('<View><RowLimit>100</RowLimit></View>');
        var collListItem = oList.getItems(camlQuery);
        clientContext.load(collListItem);

        clientContext.executeQueryAsync(onQuerySucceeded, onQueryFailed);

当我们使用“托管站点”搜索访问“ Sharepoint托管应用程序(加载项)”列表时,我们仅获得使用appcontext和跨域库将主机站点项访问加载项的结果。

有没有一种方法可以使用托管站点通过jquery访问Sharepoint加载项列表。

0 个答案:

没有答案
相关问题