1

CORS を使用して、ペーストビンからコード スニペットを読み込み、ブラウザで処理したいと考えています。

進行中のコードはこちら: http://www.boisvert.me.uk/opendata/sparql_aq+.html

コードが強調表示され、それを実行するオプションなどがあります。

ユーザーがテキストをパブリックな場所に保存してからクエリを実行する単純なサービスを提供したいと思います。

http://www.boisvert.me.uk/opendata/sparql_aq+.html?sparqlURL=whatever-url

たとえば、URL は次のとおりです。

http://pastebin.com/raw.php?i=grUU9zwE

http://www.boisvert.me.uk/opendata/sparql_aq+.html?sparqlURL=http%3A%2F%2Fpastebin.com%2Fraw.php%3Fi%3DgrUU9zwE

ただし、CORS を使用すると、リポジトリは空のファイルを返します。CORS が一部のシステム (pastebin.com など) によってブロックされているか、または何が間違っているのでしょうか?

Firefox デバッガーからの画像を添付します。要点を見逃していない限り、CORS によって返された空白の応答と、それが役立つ場合は GET ヘッダーを示しています。

Firefox ネットワーク ツール - 要求は OK ですが、結果が空白で表示されます 同じ問題、異なるシーンショット

最後に、私の CORS コード:

function CORSRequest(url) {
   var xhr = new XMLHttpRequest();

   if ("withCredentials" in xhr) {
      // Check if the XMLHttpRequest object has a "withCredentials" property.
      // "withCredentials" only exists on XMLHTTPRequest2 objects.
      xhr.open("GET", url, true);
   } else if (typeof XDomainRequest != "undefined") {
      // Otherwise, check if XDomainRequest.
      // XDomainRequest only exists in IE, and is IE's way of making CORS requests.
      xhr = new XDomainRequest();
      xhr.open("GET", url);
   } else {
      // Otherwise, CORS is not supported by the browser.
      throw new Error('CORS not supported');
   }

   if (xhr) {
      xhr.onload = function() {
         // process the response.
         document.getElementById("sparql").value = xhr.responseText;
      };
      xhr.onerror = function() {
         alert('Not loading.');
      };
   }
   xhr.send();
}
4

3 に答える 3