Rem*_*miX 2 javascript ajax rest jquery neo4j
我试图在同一台机器上使用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": {} })
});
Run Code Online (Sandbox Code Playgroud)
当我执行此代码时,在FireBug中我看到:
"NetworkError: 400 Bad Request - http://localhost:7474/db/data/cypher"
Run Code Online (Sandbox Code Playgroud)
在对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>
Run Code Online (Sandbox Code Playgroud)
这些是响应标头:
Access-Control-Allow-Origin... *
Content-Length 1065
Content-Type text/html; charset=UTF-8
Server Jetty(9.0.5.v20130815)
Run Code Online (Sandbox Code Playgroud)
当我在Chrome的Advanced Rest Client中执行相同的请求时,我确实得到了所需的响应.
如何进行我的ajax调用,以便Neo4j从Cypher查询中获得结果?
在你提供的代码片段中,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": {} })
});
Run Code Online (Sandbox Code Playgroud)
既省略,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": {} })
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1949 次 |
| 最近记录: |