2018年1月14日 星期日

Cross Domain 跨網站取得資料yahoo api

原文:https://code.tutsplus.com/tutorials/quick-tip-cross-domain-ajax-request-with-yql-and-jquery--net-10225

yahoo api 可以取得其他網站的資料
但原文html方式已經失效 剩下Json (xml未試)

Jsfiddle demo:

JS

1
2
3
4
5
6
var site = "http://data.ntpc.gov.tw/api/v1/rest/datastore/382000000A-000077-002";
var url = "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent('select * from json where url="' + site + '"') + "&format=json"; 

  $.getJSON( url, function(data) {
  $("#result").html( JSON.stringify(data) );
});

0 意見: