我想使用 javascript 从外部 Sharepoint 上下文访问 Sharepoint 数据。无论如何我可以实现它吗?
我试过以下方法:
在我的本地文件系统上创建了一个 HTML 页面。
file:///C:/Users/AD5009591/Desktop/TestRestApi.htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Untitled Page</title>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script type="text/javascript">
function getlists() {
$.ajax({
type: "GET",
contentType: "text/xml; charset=\"utf-8\"",
url: "http://syntwdd0005:5555/_vti_bin/ListData.svc",
dataType: "xml",
success: function (result) {
console.log(result);
},
error: function () {
}
});
}
</script>
</head>
<body>
<input type="button" value="getdata" onclick="javascript:getlists();" />
</body>
</html>
但是我得到了错误
Failed to load resource: the server responded with a status of 401 (Unauthorized)
XMLHttpRequest cannot load No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
最佳答案
我认为这是不可能的,因为您需要凭据才能访问 SharePoint 中的文档。如果我可以建议您,请先尝试获取 Sarepoint 凭据,然后再尝试访问文档。
通常我使用 .NET (ASP) 从我的 SharePoint 获取数据。
关于javascript - 如何使用 JavaScript 访问 SharePoint 外部的 SharePoint 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24202418/