我在弄清楚如何使OrientDB JavaScript API在Web应用程序中工作时遇到了一些困难。

我尝试搜索OrientDB Studio Web应用程序的源代码,并且能够注意到它们将Orientdb JavaScript API与一些AngularJS一起使用,这看起来非常吸引人,但是后来我通过创建一个简单的网页来尝试了这一点。 orientdb-api.js和jquery库,但是它不起作用。

这是我的网页的内容:

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script src="orientdb-api.js"></script>
    <title></title>

    <script>
        function connect() {
            var orientdb = new ODatabase("http://localhost:2480/GratefulDeadConcerts");
            var orientdbinfo = orientdb.open();
        }
    </script>
</head>
<body>
    <input type="button" value="Connect to OrientDB" onclick="connect()"/>
</body>
</html>

我在JS中使用localhost,但在我看来,从客户端访问服务器上的orientdb数据库没有任何意义。我想我缺少了一些东西,但是我仍然非常想为OrientDB使用JS API。我应该使用类似Node.js的东西还是独立的JS文件足够?

我在随附的HTML文件中运行JS代码时收到此错误消息。
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:2480/database/GratefulDeadConcerts. This can be fixed by moving the resource to the same domain or enabling CORS.

任何帮助,建议或资源将不胜感激。

问候,
杰里米

最佳答案

默认情况下未启用CORS。

将此条目添加到config/orientdb-server-config.xml

<parameter name="network.http.additionalResponseHeaders" value="Access-Control-Allow-Origin: * ;Access-Control-Allow-Credentials: true;Access-Control-Allow-Headers: Content-Type;Access-Control-Allow-Methods: POST, GET, DELETE, HEAD, OPTIONS, PATCH, CONNECT, TRACE " />

以上
<parameter value="utf-8" name="network.http.charset"/>

在冒号;后不要使用空格也很重要

关于javascript - 使用OrientDB JavaScript API构建Web应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27612752/

10-12 02:32