Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use json output from external Sparql request directly from browser?

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.

like image 356
3mpetri Avatar asked Aug 23 '11 15:08

3mpetri


1 Answers

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);
  });
like image 58
ip. Avatar answered Sep 28 '22 09:09

ip.