我正在尝试使用jQuery向Neo4j服务器发起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高级Rest客户端中进行相同的请求时,我确实得到了所需的响应。
我该如何使我的ajax调用能够从Cypher查询中获取Neo4j的结果?