Skip to content

Instantly share code, notes, and snippets.

@ekkis
Created August 24, 2015 19:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ekkis/d7086f16629ac2f8ee1e to your computer and use it in GitHub Desktop.
Save ekkis/d7086f16629ac2f8ee1e to your computer and use it in GitHub Desktop.
Provides JQuery functionality to retrieve data from the Neo4j server
var neo = {
url: 'http://localhost:7474',
user: 'neo4j',
password: 'nopass',
};
function cypher(query, success) {
query = { statements: [
{statement: query, resultDataContents: ["graph","row"]}
]};
var config = {
type:"POST",
url: neo.url + "/db/data/transaction/commit",
accepts: { json: "application/json" },
contentType: "application/json",
dataType:"json",
data: JSON.stringify(query),
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Basic ' + btoa(neo.user + ':' + neo.password));
},
success: success,
error: function(jqXHR, textStatus, errorThrown) {
$('#error').text(textStatus + '/' + errorThrown);
}
};
$.ajax(config);
}
cypher('match (n) return n', function(data) {
var ls = data.results[0].data;
for (var k in ls) {
var o = ls[k].row[0];
// o is the node and its attributes can be accessed e.g. o.Name
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment