#できるらしい(らしい)
ということであちこち見ながらこしらえてみたのがこちら
html
1<html> 2<input type="button"value="JSONファイルを取得する" onclick="getJSON()"> 3<input type="button"value="TEST" onclick="TEST()"> 4<script> 5 6function TEST(){ 7 console.log("hoge"); 8} 9 10function getJSON(){ 11 var xmlHttpRequest = new XMLHttpRequest(); 12 xmlHttpRequest.onreadystatechange = function(){ 13 if( this.readyState == 4 && this.status == 200 ){if( this.response ){console.log(this.response);}} 14 } 15 16 xmlHttpRequest.open( 'GET', ' http://weather.livedoor.com/forecast/webservice/json/v1?city=130010', true ); 17 xmlHttpRequest.responseType = 'json'; 18 xmlHttpRequest.send( null ); 19} 20</script> 21</html>
で、結果がこれ。
「No 'Access-Control-Allow-Origin'」……ふーん。ググってみるとこっちと向こうでドメインが違うとこうなるんだとか。
……いやドメイン違うのは当たり前でしょ誰も使えないじゃんどうすんの。
キレ気味にコード内のURLを検索窓に投げ込んだところ普通に見せてくれました。ますますわけがわかりません。
#CORSとやらがあるらしい
サーバー側で設定変えるらしいです。俺のサーバーじゃねえんだゾ何言ってんだこいつ。
#無理
4時間粘りましたがどうにもなりません。普通にあちこちで使われているはずの技術なので何か手があるのは間違い無いと思うんですが……。どなたか助けてください……
回答3件
あなたの回答
tips
プレビュー