My current challenge involves retrieving data from a Sesame Triplestore using ajax. It seems like I might be dealing with a CORS issue, and to address this, I am considering utilizing the CORS Filter. Is my assumption on point, or is there something specific in the code that needs altering?
$(document).ready(function() {
$.ajax({
url: 'http://localhost:8080/openrdf-sesame/repositories/Test12',
dataType: 'jsonp',
data: {
queryLn: 'SPARQL',
query: "SELECT * WHERE { ?s ?p ?o }",
limit: 100,
infer: 'true',
Accept: 'application/sparql-results+json'
},
success: displayData,
error: displayError
});
});
function displayError(xhr, textStatus, errorThrown) {
alert(textStatus);
alert(errorThrown);
}
function displayData(data) {
var header = $('#result thead').append('<tr/>');
$.each(data.head.vars, function(key,value) {
header.append("<th>" + value + "</th>");
});
$.each(data.results.bindings, function(index, bs) {
var row = $('<tr/>');
$.each(data.head.vars, function(key, varname) {
row.append("<td>" + bs[varname].value + "</td>");
});
$("#result tbody").after(row);
});
}
The browser console displays the following error:
Resource interpreted as Script but transferred with MIME type application/sparql-results+json: "http://localhost:8080/openrdf-sesame/repositories/Test12?callback=jQuery213…=100&infer=true&Accept=application%2Fsparql-results%2Bjson&_=1429660808937". jquery-2.1.3.min.js:4
send jquery-2.1.3.min.js:4
n.extend.ajax jquery-2.1.3.min.js:4
(anonymous function) index_wip3.html:10
j jquery-2.1.3.min.js:2
k.fireWith jquery-2.1.3.min.js:2
n.extend.ready jquery-2.1.3.min.js:2
I jquery-2.1.3.min.js:2
Uncaught SyntaxError: Unexpected token : Test12:2
When attempting to replace application/sparql-results+json with application/json, the error remains unchanged.
Switching the dataType to "json" instead of "jsonp" results in a different error message:
XMLHttpRequest cannot load http://localhost:8080/openrdf-sesame/repositories/Test12?queryLn=SPARQL&que…HERE+%7B+%3Fs+%3Fp+%3Fo+%7D&limit=100&infer=true&Accept=application%2Fjson. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.