Skip to content

Instantly share code, notes, and snippets.

@frogcat
Created December 1, 2015 11:59
Show Gist options
  • Save frogcat/545d0cb798f79a707ca4 to your computer and use it in GitHub Desktop.
Save frogcat/545d0cb798f79a707ca4 to your computer and use it in GitHub Desktop.
SPARQL Endpoint に AJAX でアクセスする方法 ref: http://qiita.com/frogcat/items/beb8888bb334699e21ed
http://ja.dbpedia.org/sparql
<script>
var endpoint = "http://ja.dbpedia.org/sparql";
var query = "select (count(*) as ?count) where {?s ?p ?o.}";
var x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200)
document.body.appendChild(document.createTextNode(x.responseText));
};
x.open("GET", endpoint + "?query=" + encodeURIComponent(query), true);
x.setRequestHeader("Accept", "application/sparql-results+json");
x.send();
</script>
<script>
var endpoint = "http://ja.dbpedia.org/sparql";
var query = "select (count(*) as ?count) where {?s ?p ?o.}";
var x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200)
document.body.appendChild(document.createTextNode(x.responseText));
};
x.open("POST", endpoint, true);
x.setRequestHeader("Accept", "application/sparql-results+json");
x.setRequestHeader("Content-Type", "application/sparql-query");
x.send(query);
</script>
<script>
var endpoint = "http://ja.dbpedia.org/sparql";
var query = "select (count(*) as ?count) where {?s ?p ?o.}";
var x = new XMLHttpRequest();
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200)
document.body.appendChild(document.createTextNode(x.responseText));
};
x.open("POST", endpoint, true);
x.setRequestHeader("Accept", "application/sparql-results+json");
x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
x.send("query=" + encodeURIComponent(query));
</script>
select (count(*) as ?count) where {?s ?p ?o.}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment