繁体   English   中英

如何使用JavaScript在SharePoint外部访问SharePoint数据?

[英]How to access SharePoint data outside SharePoint using JavaScript?

我想使用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中获取数据。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM