Main Page/test: Difference between revisions
Jump to navigation
Jump to search
(Jason.nlw changed the content model of the page Main Page/test from "wikitext" to "JavaScript") Tag: content model change |
No edit summary |
||
Line 1: | Line 1: | ||
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 ); | |||
} | |||
); |
Latest revision as of 13:31, 18 January 2023
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 );
}
);