gpt4 book ai didi

javascript - 在简单网页中使用 SharePoint 2013 跨域库 : is it possible?

转载 作者:数据小太阳 更新时间:2023-10-29 04:51:12 25 4
gpt4 key购买 nike

我在服务器上托管了一个网页,例如 http://SVR1/path/index.html,我想访问本地 SharePoint 站点中的一些列表项托管在另一台服务器上,例如 http://SVR2/sites/mySite/

我正在使用的(不受我控制的)SharePoint 的当前安装不允许部署 SharePoint 托管和提供商托管的应用程序,因此我正在尝试使用 SharePoint 跨域库来访问所需的列表项从一个纯粹的外部 HTML5/JS/CSS3 页面。作为用户,我对我的 SharePoint 网站中的列表具有完全访问权限,因此我想阅读其中的项目应该没有问题。

下面找到一个例子here ,我的页面如下:

<!doctype html>
<html>
<head>
<!-- Title -->
<title>Application Template</title>
<script language="javascript" type="text/javascript" src="js/jquery.js"></script>
<script language="javascript" type="text/javascript">

var hostweburl = "http://SVR2/sites/mySite";
var appweburl = "http://SVR1/path";

// Load the required SharePoint libraries
$(document).ready(function () {

$("#renderList").html("Requesting Lists...");

// resources are in URLs in the form:
// web_url/_layouts/15/resource
var scriptbase = hostweburl + "/_layouts/15";

// Load the js files and continue to the successHandler
$.getScript(scriptbase + "/SP.RequestExecutor.js", execCrossDomainRequest);
});

///////////////////////////////////////////////////////
// Function to prepare and issue the request to get
// SharePoint data
function execCrossDomainRequest() {
// executor: The RequestExecutor object
// Initialize the RequestExecutor with the app web URL.
var executor = new SP.RequestExecutor(appweburl);

// Issue the call against the host web.
// To get the title using REST we can hit the endpoint:
// hostweburl/_api/web/lists/getbytitle('listname')/items
// The response formats the data in the JSON format.
// The functions successHandler and errorHandler attend the
// sucess and error events respectively.
executor.executeAsync(
{
url: hostweburl + "/_api/web/lists",
method: "GET",
headers: { "Accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
}
);
}

///////////////////////////////////////////////////////
// Function to handle the success event.
// Prints the data to the page.
function successHandler(data) {
var jsonObject = JSON.parse(data.body);
var listsHTML = "";

var results = jsonObject.d.results;
for (var i = 0; i < results.length; i++) {
listsHTML = listsHTML +
"<p><h1>" + results[i].Title +
"</h1>" + results[i].Body +
"</p><hr>";
}

document.getElementById("renderList").innerHTML =
listsHTML;
}

///////////////////////////////////////////////////////
// Function to handle the error event.
// Prints the error message to the page.
function errorHandler(data, errorCode, errorMessage) {
document.getElementById("renderList").innerText =
"Could not complete cross-domain call: " + errorMessage;
}
</script>

</head>

<body>
<h1 id="Root Page" style="text-align:center;">This is the home page</h1>
<div id="renderList">Placeholder</div>
</body>
</html>

当我在浏览器中加载页面时,在 javascript 控制台中出现错误:“ Uncaught Error :无效的字段或参数 requestInfo.url。”。

我的印象是问题出在变量 appweburl 的内容中,在我发现的所有示例中,SharePoint 都将其作为 URL 中查询部分的一部分提供。但这意味着提供商托管的应用程序已部署在 SharePoint 中——这是我无法做到的——并且该应用程序正在调用其远程托管的对应应用程序。

所以问题是:是否可以在完全不属于 SharePoint 的页面中使用 SharePoint 跨域库,如果可以,我应该如何设置 hostweburlappweburl 也许还有其他访问 SharePoint 列表的东西?

提前致谢。

最佳答案

你提到的两个 URL,appwebUrl 和 hostwebUrl 确实是为在应用程序中使用而设计的,所以我认为你不应该使用跨域库。

如果您只是使用非应用程序方式连接怎么办?例如,您可以调用自定义 Web 服务(在共享点之外),它可以通过 CSOM 连接到您的 SP 站点,或者您可以直接在 javascript 中执行此操作。

关于javascript - 在简单网页中使用 SharePoint 2013 跨域库 : is it possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24182278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com