问题描述
我在弄清楚如何让OrientDB JavaScript API在网络应用中运行时遇到了一些困难。
I'm having a bit of difficulty in figuring out how to get the OrientDB JavaScript API to work in a web app.
我试着搜索源代码OrientDB Studio网络应用程序,并注意到他们使用orientdb JavaScript API以及一些看起来非常迷人的AngularJS,但后来我尝试创建一个导入orientdb-api.js的简单网页。 jquery库,它不起作用。
I tried searching into the source code of the OrientDB Studio web app and was able to notice that they use the orientdb JavaScript API along with some AngularJS, which looks very fascinating, but then I tried on my side by creating a simple web page that imported the orientdb-api.js and the jquery library, and it did not work.
这是我的网页内容:
<!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文件呢?
I'm using localhost in my JS, but it just seems to me that it does not make sense to access my orientdb database on the server from the client. I think I'm missing something, but still I'd really like to use the JS API for OrientDB. Should I use something like Node.js or is the standalone JS file sufficient?
当我在随附的HTML文件中运行JS代码时,我收到此错误消息。
I get this error message when I run the JS code in the enclosed HTML file.
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.
我们非常感谢任何帮助,建议或资源。
Any help, advice, or resources would be greatly appreciated.
问候,
Jeremie
Regards,Jeremie
推荐答案
默认情况下未启用CORS。
CORS is not enabled by default.
在中添加此条目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"/>
在冒号; $ c $之后不使用空格也很重要c>
这篇关于使用OrientDB JavaScript API构建Web应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!