Can anybody show me an example of how to load the .srj files that result from querying a Sesame SPARQL endpoint using jQuery's getJSON? I've tried setting the Accept header and other tricks but I still see the 200 code and apparently no error, but the content of the file is not loaded.
$.getJSON("http://localhost:8090/openrdf-sesame/repositories/myrepo?queryLn=SPARQL&query=QUERY&limit=none&infer=true&Accept=application%2Fsparql-results%2Bjson",
{
},
function(data) {
alert('data = ', data);
});
I've tried something like this and countless other variants and it still doesn't work. I have to mention that I tested both cases:
- Tomcat is not mounted in Apache, case in which we have a cross-domain request - and I tried setting everything that was needed in the browser;
- Tomcat mounted in Apache - which as far as I know did not required anything else to work, but still no success.
Here is the Request Header:
Accept:application/json, text/javascript, */*; q=0.01
Accept-Encoding:gzip, deflate
Accept-Language:en-us,en;q=0.5
Connection:keep-aliveHost:localhost:8090
Origin:http://localhost
Referer:http://localhost/d3v280/examples/ablodvis/localtest.html
User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0
Here is the Response Header:
Content-Disposition:attachment; filename=query-result.srj
Content-Language:en-US
Content-Type:application/sparql-results+json;charset=UTF-8
Date:Mon, 28 May 2012 14:06:06 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked
As you can see I do get a result in the query-result.srj file, but I don't know how to access it. I would very much prefer the first version to work, but apparently I am missing something. All the similar getJSON requests worked.
Here is the request that almost works:
$.ajax({
beforeSend: function(xhrObj){
xhrObj.setRequestHeader("Accept","application/sparql-results+json");
},
dataType: 'jsonp',
url: queryUrl,
success: function(data) {
// callback code here
console.log("source: " + data.length)
alert('success!');
}
});
However it throws an "invalid label error" in Firefox, while in Chrome it doesn't throw any error, but as I see on the second line of my query-results.srj file it shows Uncaught SyntaxError: Unexpected token :. Here is how the first lines of the response look like:
{
"head": {
"vars": [ "s", "p", "o", "r" ]
},
"results": {
"bindings": [ ...
This time I am able to see the request done successfully and see it in my browser (at least in debug mode in both Chrome and Firefox). Should I understand that the jsonp trick doesn't work with Sesame? If I take the answer from Sesame, copy it in a file, rename it file.js and load it with $.getJSON it works ok...I don't want to have any server-side code for this application, just to process the result of a SPARQL query directly. I've easily setup up the rest of the sources (WorldBank, DBPedia, and others) through $.getJSON or $.ajax.
Best regards!