load .srj files with jQuery's ajax or getJSON

KurruptOwner

New Member
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.\[code\]$.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 = 'http://stackoverflow.com/questions/10784271/, data);});\[/code\]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 across-domain request - and I tried setting everything that wasneeded in the browser;[*]Tomcat mounted in Apache - which as far as I know did not requiredanything else to work, but still no success.Here is the Request Header:\[code\]Accept:application/json, text/javascript, */*; q=0.01Accept-Encoding:gzip, deflateAccept-Language:en-us,en;q=0.5Connection:keep-aliveHost:localhost:8090Origin:http://localhostReferer:http://localhost/d3v280/examples/ablodvis/localtest.htmlUser-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0\[/code\]Here is the Response Header:\[code\]Content-Disposition:attachment; filename=query-result.srjContent-Language:en-USContent-Type:application/sparql-results+json;charset=UTF-8Date:Mon, 28 May 2012 14:06:06 GMTServer:Apache-Coyote/1.1Transfer-Encoding:chunked\[/code\]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:\[code\] $.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!'); } });\[/code\]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:\[code\]{"head": { "vars": [ "s", "p", "o", "r" ]}, "results": { "bindings": [ ...\[/code\]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!
 
Top