2017-03-21 4 views
0

ウェブサイトのHTMLに数字を入力するための小さなJSを書いています。私のD3コードはこのエラーを投げている、私はローカルのファイルを実行したとき、それは働いたが、私は私のホスティングにアップロードしたときに、リチウム:D3 Googleシートのアクセス制御 - 許容元のエラー

XMLHttpRequest cannot load https://docs.google.com/spreadsheets/d/12jMwpmqdbUUfcMHWg2GwGvu-d9BhaJOEsWjK1eoqHRc/pub?output=csv . No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' https://alanhovorka.com ' is therefore not allowed access.

「私はここに答えのいくつかを読んだが、彼らはドンD3がCSVとしてウェブに公開されているGoogleシートからデータを取得したときに直接対処するようです。 CORSがD3で動作するかどうか、そして卓上を使用する必要があるかどうかについて、私は混乱しています。私のCORSに関する知識は限られていますが、それは最も単純な解決策のようです。また、私は卓上を稼働させることができませんでした。私は、その長期的な実行可能性についての懸念を読んできました。

は、ここでスプレッドシートのコールと私のJSです: ウェブサイトのおかげalanhovorka.com

d3.csv("https://docs.google.com/spreadsheets/d/12jMwpmqdbUUfcMHWg2GwGvu-d9BhaJOEsWjK1eoqHRc/pub?output=csv", function(error, data) { 
    d3.select("#requests").selectAll('h1').data(data).append("h1").style("color", "#387284").text(function(d) { 
     return d.rqt_count; 
    }); 
    d3.select("#agencies").selectAll('h1').data(data).append("h1").style("color", "#387284").text(function(d) { 
     return d.agency_cnt; 
    }); 
    d3.select("#records").selectAll('h1').data(data).append("h1").style("color", "#387284").text(function(d) { 
     return d.records_obt_cnt; 
    }); 
    d3.select("#pages").selectAll('h1').data(data).append("h1").style("color", "#387284").text(function(d) { 
     return d.pg_cnt; 
    }); 
}); 

です!

答えて

1

My knowledgeof CORS is limited, but it seems like it would be the simplest the solution.

これはありません。あなたはGoogleのサーバーを制御しないので、これらのヘッダーを応答に追加することはできません。

代わりにプロキシまたはget the data through the APIを使用する必要があります。

関連する問題