neo4j-节点创建(错误请求)错误

时间:2014-01-19 17:37:49

标签: jquery ajax neo4j

我正在尝试使用REST api jquery ajax创建一个节点我已经尝试了下面的代码我似乎没有在语法下面找到任何错误所以请帮助。这是代码:

$.ajax({
            url: "http://localhost:7474/db/data/cypher",
            accepts: "application/json; charset=UTF-8",
            //contentType:"application/json",
            dataType:"json",
            data:{
                "query" : "CREATE (n:Person { props } ) RETURN n",
                "params" : {
                    "props" : {
                          "position" : "Developer",
                          "name" : "Michael",
                          "awesome" : true,
                          "children" : 3
                    }
                }
            },
            type:"POST",
            success:function(data,xhr,status)
            {
                console.log(status);
            },
            error:function(xhr,err,msg){
                console.log(xhr);
                console.log(err);
                console.log(msg);
            }
        });

执行时我收到Bad Request错误 但就在此之前我执行了“start n = node(*)return n”,它工作正常 请指出错误...非常感谢

1 个答案:

答案 0 :(得分:2)

您发送的数据似乎是作为url-parameters发送的,您发送的请求就像是:

  

查询= CREATE +(N%3APerson +%7B +道具+%7D +)+ RETURN + N&安培; PARAMS%5Bprops%5D%5Bposition%5D =开发人员&安培; PARAMS%5Bprops%5D%5Bname%5D =迈克尔&安培; PARAMS%5Bprops%图5D%5Bawesome%5D =真安培; PARAMS%5Bprops%5D%5Bchildren%5D = 3

但是neo4j希望以纯文本形式发布请求(不是以url编码形式)

希望你现在能够理解这个问题

编辑: 试试这个;

var d = { "query" : "CREATE (n:Person { props } ) RETURN n", "params" : { "props" : { "position" : "Developer", "name" : "Michael", "awesome" : true, "children" : 3 } } };
$.ajax({
            url: "http://localhost:7474/db/data/cypher",
            accepts: "application/json; charset=UTF-8",
            contentType:"application/json",
            dataType:"json",
            data:JSON.stringify(d),
            type:"POST",
            success:function(data,xhr,status)
            {
                console.log(status);
            },
            error:function(xhr,err,msg){
                console.log(xhr);
                console.log(err);
                console.log(msg);
            }
        });