function makeSPARQLQuery( endpointUrl, sparqlQuery, doneCallback ) {
var settings = {
headers: { Accept: 'application/sparql-results+json' },
data: { query: sparqlQuery }
};
return $.ajax( endpointUrl, settings ).then( doneCallback );
}
var endpointUrl = 'https://query.wikidata.org/sparql',
sparqlQuery = "#Cats\n" +
"SELECT ?item ?itemLabel \n" +
"WHERE \n" +
"{\n" +
" ?item wdt:P31 wd:Q146. # Must be of a cat\n" +
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"[AUTO_LANGUAGE],en\". } # Helps get the label in your language, if not, then en language\n" +
"}";
makeSPARQLQuery( endpointUrl, sparqlQuery, function( data ) {
$( 'body' ).append( $( '<pre>' ).text( JSON.stringify( data ) ) );
console.log( data );
}
);