[英]Executing a Cypher query on Neo4j using jQuery
我正在尝试使用jQuery对Neo4j Server进行Ajax调用,两者都在同一台机器上,但是我在响应中不断出错。
这是我写ajax调用的方式:
var request = $.ajax({
type: "POST",
url: "http://localhost:7474/db/data/cypher",
accepts: "application/json",
dataType: "json",
contentType:"application/json",
data: JSON.stringify({ "query" : "MATCH n RETURN n LIMIT 1", "params": {} })
});
当我执行此代码时,在FireBug中,我看到:
"NetworkError: 400 Bad Request - http://localhost:7474/db/data/cypher"
在对POST请求的响应中,我找到了以下正文:
<html><head><title>Error</title></head><body><p><pre>WebApplicationException
at org.neo4j.server.rest.repr.formats.HtmlFormat.serializeMapping(HtmlFormat.java:348)
at org.neo4j.server.rest.repr.RepresentationFormat.serializeMapping(RepresentationFormat.java:73)
at org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:39)
at org.neo4j.server.rest.repr.OutputFormat.assemble(OutputFormat.java:215)
at org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:147)
at org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:130)
at org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:67)
at org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:101)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:139)
at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)
at java.lang.Thread.run(Thread.java:745)</pre></p></body></html>
这些是响应头:
Access-Control-Allow-Origin... *
Content-Length 1065
Content-Type text/html; charset=UTF-8
Server Jetty(9.0.5.v20130815)
当我在Chrome的Advanced Rest Client中执行相同的请求时,确实得到了所需的响应。
我该如何打电话给ajax,以便Neo4j会给我Cycy查询的结果?
在代码段中,您提供了一个更复杂的Accepts
标头,它是Neo4j无法处理的。 我使用了以下片段:
var request = $.ajax({
type: "POST",
url: "http://localhost:7474/db/data/cypher",
accepts: { json: "application/json" },
dataType: "json",
contentType:"application/json",
data: JSON.stringify({ "query" : "MATCH n RETURN n LIMIT 1", "params": {} })
});
两者都省略, accepts
和dataType
似乎也可以工作:
var request = $.ajax({
type: "POST",
url: "http://localhost:7474/db/data/cypher",
contentType:"application/json",
data: JSON.stringify({ "query" : "MATCH n RETURN n LIMIT 1", "params": {} })
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.