我想使用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.
答案 0 :(得分:0)
我认为这是不可能的,因为您需要凭据才能访问SharePoint中的文档。如果我可能会建议您,请先尝试获取Sarepoint凭据,然后再尝试访问文档。
通常我使用.NET(ASP)从我的SharePoint获取数据。