Created
August 24, 2015 19:12
-
-
Save ekkis/d7086f16629ac2f8ee1e to your computer and use it in GitHub Desktop.
Provides JQuery functionality to retrieve data from the Neo4j server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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