如何用jQuery查询neo4j图 [英] How to query neo4j graph with jQuery
问题描述
[早期版本在我试用时已经更新]
[earlier version has been updated as I try things]
我知道一些javascript,我有一个工作的neo4j数据库我可以在控制台中使用cypher进行查询。此外,这个卷曲有效:
I do know some javascript and I have a working neo4j db I can query with cypher in a console. Also, this curl works:
curl -X POST http://
localhost:7474 / db / data / cypher
--data @ test.json -H
accept:application / json -H content-type:application / json -H
X-Stream:true
curl -X POST http://
localhost:7474/db/data/cypher
--data @test.json -H accept:application/json -H content-type:application/json -H X-Stream:true
但是我想用jQuery $ ajax调用得到结果 - 真的,任何方式我都可以在javascript中获得JSON结果,不必是jQuery
But I want to get results with jQuery $ajax call -- really, any way I can get the JSON result in javascript, doesn't have to be jQuery
此函数产生消息:
500意外字符(' q'(代码113)):在[来源:
java.io.StringReader]预期有效值
(数字,字符串,数组,对象,'true','false'或'null') @ 56f31ac6; line:1,column:2]
500 Unexpected character ('q' (code 113)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: java.io.StringReader@56f31ac6; line: 1, column: 2]
提前感谢,
Karl
thanks in advance, Karl
function getsomething() {
var serverURL = "http://localhost:7474/db/data"
$.ajax({
type:"POST",
url: serverURL + "/cypher",
accepts: "application/json",
dataType: "json",
contentType:"application/json",
headers: {
"X-Stream": "true"
},
data:{ "query" : "start n = node(1) return n;" },
success: function(data, textStatus, jqXHR){
alert(textStatus);
},
error: function(jqXHR, textStatus, errorThrown){
alert(errorThrown);
console.log(textStatus);
}
});//end of ajax
} //end of getSomething()
getsomething();
推荐答案
您需要使用HTTP方法 POST
与 db / data / cypher
端点进行通信。所以尝试设置
You need to use HTTP method POST
to talk to db/data/cypher
endpoint. So try to set
type: "POST",
致电 $。ajax
。
免责声明:没试过自己,只是从臀部拍摄
disclaimer: didn't try that myself, just a shoot from the hip
你需要包装数据部分使用 JSON.stringify
:
you need to wrap the data part using JSON.stringify
:
data: JSON.stringify({
"query" : "start n = node(*) return n;",
"params" : {}
}),
这篇关于如何用jQuery查询neo4j图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!