3

[earlier version has been updated as I try things]

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

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

This function produces the message:

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]

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();

1 Answer 1

2

You need to use HTTP method POST to talk to db/data/cypher endpoint. So try to set

type: "POST",

in your call to $.ajax.

disclaimer: didn't try that myself, just a shoot from the hip

update

you need to wrap the data part using JSON.stringify:

 data: JSON.stringify({
       "query" : "start n = node(*) return n;",
       "params" : {}
     }),
Sign up to request clarification or add additional context in comments.

5 Comments

Should have mentioned - I began with POST, got the result mentioned then tried GET for the heck of it and put that in snippet above by mistake
see the Update section in my answer above
This worked - and I'm very curious to know where you know this/learned this from? The amount of time "driving in the dark" is really frustrating. And BIG THANKS for following through!
you're welcome, I've found a code snippet from a project I've used that.
I don't need to wrap my data in Json stringification. a normal object works ok for me

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.