Lets say I want json file generated from Dbpedia sparql endpoint http://dbpedia.org/sparql
For now I'm just making a request and it automatically downloads json file to my disk, and I use it locally.
How to use json directly from the endpoint? For example, how to input the request by itself in my code instead of inputting locally saved json file?
More concrete, I request for Federer stats:
select * where {<http://dbpedia.org/resource/Roger_Federer> ?p ?o filter(lang(?o) = 'en')}
Saving output as winner.json and fetching it with this:
$.getJSON('json/winner.json', function(json) {
for(var i = 0; i < json["results"]["bindings"].length; i++) {
$('#winner').append(json["results"]["bindings"][i]["o"].value + '<br /><br />');
};
});
I want to be able to fetch json directly from the server with my script.
Do I need to play with HTML accept headers or something completely else? Thanks on any tip.
Just do:
$.getJSON("http://dbpedia.org/sparql?default-graph-uri=http%3A%2F%2Fdbpedia.org&query=select+*+where+%7B%3Chttp%3A%2F%2Fdbpedia.org%2Fresource%2FRoger_Federer%3E+%3Fp+%3Fo+filter%28lang%28%3Fo%29+%3D+%27en%27%29%7D%0D%0A&debug=on&timeout=&format=application%2Fsparql-results%2Bjson&save=display&fname=",
{},
function(data) {
console.log('data = ', data);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With