Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-14-2019 02:11 PM
I have created a geohash graph for NYC Cabs data, now the next step is to plot it within a map, for that i choosed to use Leaflet as a javascript mapping library.
my problem is getting data from Neo4j database to JavaScript code.
i found in stackoverflow that you have answered a smilar question by using ajax :
var body = JSON.stringify({
statements: [{
statement: 'MATCH (n) RETURN count(n)'
}]
});
$.ajax({
url: "http://localhost:7474/db/data/transaction/commit",
type: "POST",
data: body,
contentType: "application/json"
})
.done(function(result){
console.log(result);
})
.fail(function(error){
console.log(error.statusText);
});
however this solution doesn't work for me since i get "unauthorized" in console when i run it.
i understand that i need to pass authentification in the url, so how to do that ?
Solved! Go to Solution.
01-15-2019 09:25 AM
Thanks @michael.hunger for you reply ,that helped me to find the solution:
the magic of authentification need to be passed in header with ajax function beforeSend :
var body = JSON.stringify({
statements: [{
statement: 'MATCH (n) RETURN n.geohash'
}]
});
$.ajax({
url: "http://localhost:7474/db/data/transaction/commit",
type: "POST",
data: body,
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "yourneo4jpassword"));
}}
)
.done(function(result){
console.log(result);
})
.fail(function(error){
console.log(error.statusText);
});
hope that help someone in the future 🙂
01-15-2019 01:06 AM
You have to provide the auth to the database too, e.g. by the user
Or if it's readonly you can also hardcode the RO user.
Better to use the javascript bolt driver which handles that for you.
For the http API you have to figure out how to do that with jquery, see here:
01-15-2019 09:25 AM
Thanks @michael.hunger for you reply ,that helped me to find the solution:
the magic of authentification need to be passed in header with ajax function beforeSend :
var body = JSON.stringify({
statements: [{
statement: 'MATCH (n) RETURN n.geohash'
}]
});
$.ajax({
url: "http://localhost:7474/db/data/transaction/commit",
type: "POST",
data: body,
contentType: "application/json",
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa("neo4j"+ ":" + "yourneo4jpassword"));
}}
)
.done(function(result){
console.log(result);
})
.fail(function(error){
console.log(error.statusText);
});
hope that help someone in the future 🙂
All the sessions of the conference are now available online