XMLHttpRequest 上的身份验证错误

Authentification error on a XMLHttpRequest

我正在尝试获取 http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people

给出的 JSON 字符串

所以我写了这段代码:

<p id="liste"></p>

   <script>

        var people = new XMLHttpRequest();
        people.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                obj = JSON.parse(this.responseText);
                document.getElementById("liste").innerHTML = objet.list.entries[0].entry.firstName + objet.list.entries[0].entry.lastName + "<br/>" + objet.list.entries[boucle].entry.email;
            }
        };
        people.open('GET', 'http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people', true, 'admin', 'admin');
        people.send();

    </script> 

但这给了我 401 身份验证错误。此外,当我手动进入 link 时,我会看到正常的登录弹出窗口,我可以在上面使用 admin/admin 登录并获得预期的字符串。

这是我因 XMLHttpRequest 而收到的两个控制台错误:

localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people Failed to load resource: the server responded with a status of 401 (Unauthorized)
new-page:1 XMLHttpRequest cannot load http://localhost:8080/alfresco/api/-default-/public/alfresco/versions/1/people. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8081' is therefore not allowed access. The response had HTTP status code 401.

目前,为了继续我的开发,我手动复制了代码中的字符串,因为我找不到问题出在哪里,但它不是真正的解决方案...所以如果有人知道我该怎么做解决了我的问题 我非常感谢 him/her !

如果您不需要更多详细信息,您可以找到错误 here 的文档。

P.S :这是在我为 Alfresco Share 创建的页面(.ftl)上。我有一个在端口 8080 上使用 Maven 运行 生成的露天实例,在这个 Share 实例上也使用 Maven 运行 在 8081 上生成。所以也许我必须在 xml 中添加一些定义页数?

如果您在分享页面中,那么在关注的帮助下,您可以获得所有用户。

<script>
    Alfresco.util.Ajax.jsonGet({
        url : Alfresco.constants.PROXY_URI + "api/people",
        successCallback : {
            fn : function(res) {
                var results = Alfresco.util.parseJSON(res.serverResponse.responseText);
                console.log(results.people[0].firstName);
            },
            scope : this,

        },
        failureCallback : {
            fn : function() {
            },
            scope : this
        }
    });
</script>