2015-09-30 46 views
0

我试图通过ajax请求在两个节点之间创建关系。以下是我的代码 -通过Ajax请求在Neo4j中创建关系

var restServerURL = "http://localhost:7474/db/data"; 
$.ajax({ 
    async: false, 
    type: "POST", 
    url: restServerURL + "/node/1/relationships", 
    dataType: "json", 
    to: "http://localhost:7474/db/data/node/2", 
    contentType: "application/json", 
    success: function(data, xhr, textStatus) { 
     console.log("success"+data); 
    }, 
    error: function(xhr) { 
     window.console && console.log(xhr); 
     console.log("error"); 
    }, 
    complete: function() { 
     console.log("complete function"); 
    } 
}); 

我可以设置任何参数吗?它不是在Neo4j中创建关系并进入错误模块。在url中,属性1和2是节点的id属性。

的关系源节点信息 -

<id>:584 
name:trt 
id:1 
index:1 
weight:0 
x:250.48512294215675 
y:138.53438454446515 
px:250.79081359249457 

目标节点信息对于关系 -

<id>:583 
name:t 
id:2 
index:2 
weight:0 
x:335.564840711768 
y:255.65841599561486 
px:335.4984412139487 
py:255.42282166757116 

请建议的解决方案/整改。

回答

0

在要传递到$.ajax()你应该删除这个属性/线路的对象:

to: "http://localhost:7474/db/data/node/2", 

,并替换为:

data: {"to": "http://localhost:7474/db/data/node/2", "type": "REL_TYPE_HERE"} 

另外,一定要指定correct authentication header如果启用验证为Neo4j。响应的状态代码是什么?

+0

非常感谢William的回复。我尝试了你告诉的方式,现在抛出下面的错误 - –

+0

“data is {”readyState“:4,”responseText“:”{\ r \ n \“message \”:\“无法识别的令牌' [line:1,column:3] \“,\ r \ n \”exception \“:\”BadInputException \“,\ r \ n \”fullname \“:\”org.neo4j.server.rest.repr。 BadInputException \“,\ r \ n \”stackTrace \“:[\”org.neo4j.server.rest.repr.formats.JsonFormat.readMap(JsonFormat.java:94)\“,\”org.neo4j.server。 rest.web.RestfulGraphDatabase.createRelationship(RestfulGraphDatabase.java:570)\“,\”java.lang.reflect.Method.invoke(Unknown Source)\“, –

+0

\”org.neo4j.server.rest.transactional.TransactionalRequestDispatcher。 (“TransactionalRequestDispatcher.java:139)\”,\“org.neo4j.server.rest.dbms.AuthorizationFilter.doFilter(AuthorizationFilter.java:120)\”,\“java.lang.Thread.run(Unknown Source)\ “],\ r \ n \”cause \“:{\ r \ n \”message \“:\”Unrecognized token'to':was expected [line:1,column:3] \“,\ r \ n \“errors \”:[{\ r \ n \“mes sage \“:\”无法识别的标记'改为':期待[line:1,column:3] \“,\ r \ n \”code \“:\”Neo“[0123]] []] –