javascript - CORS to read a text file from a pastebin -
i hoping use cors load code snippets pastebin, process them in browser.
some code in progress here: http://www.boisvert.me.uk/opendata/sparql_aq+.html
the code highlighted , there options run etc.
i'd provide simple service, user saves text anywhere public, queries:
http://www.boisvert.me.uk/opendata/sparql_aq+.html?sparqlurl=whatever-url
for example, url is:
http://pastebin.com/raw.php?i=gruu9zwe
but when using cors, repository returns empty file. cors blocked systems (e.g. pastebin.com?) or doing wrong?
i attach images firefox debugger, showing, unless i'm missing point, blank response returned cors, , in case helps, headers.
finally, cors code:
function corsrequest(url) { var xhr = new xmlhttprequest(); if ("withcredentials" in xhr) { // check if xmlhttprequest object has "withcredentials" property. // "withcredentials" exists on xmlhttprequest2 objects. xhr.open("get", url, true); } else if (typeof xdomainrequest != "undefined") { // otherwise, check if xdomainrequest. // xdomainrequest exists in ie, , ie's way of making cors requests. xhr = new xdomainrequest(); xhr.open("get", url); } else { // otherwise, cors not supported browser. throw new error('cors not supported'); } if (xhr) { xhr.onload = function() { // process response. document.getelementbyid("sparql").value = xhr.responsetext; }; xhr.onerror = function() { alert('not loading.'); }; } xhr.send(); }
Comments
Post a Comment