Skip to content

Instantly share code, notes, and snippets.

@RadianSmile
Last active May 18, 2017 14:19
Show Gist options
  • Save RadianSmile/9e48cd4fa58eaa04426f6de87f52c2a7 to your computer and use it in GitHub Desktop.
Save RadianSmile/9e48cd4fa58eaa04426f6de87f52c2a7 to your computer and use it in GitHub Desktop.
(function($) {
$.getWeatherJSON = function ( url , callback ){
$.getJSON (url , function (data){
if (data && data.query && data.query.results && data.query.results.channel.item.forecast && data.query.results.channel.item.forecast[3] ){ // if data.query.results exist , do the following action.
callback (data)
}else {
console.info("reloading : ",url)
$.getWeatherJSON(url,callback)
}
})
}
})(jQuery)
@RadianSmile
Copy link
Author

RadianSmile commented May 17, 2017

使用方式

  1. 引入此程式檔:在 html 引入 jquery 後的地方加上這一行。
<script type="text/javascript" src="https://rawgit.com/RadianSmile/9e48cd4fa58eaa04426f6de87f52c2a7/raw/017c2cda22d7e904f538da7f45de3750d3b6de91/assign5.getjson.patch.js"></script>
  1. 對 yahoo 存取資料,請使用 $.getWeatherJSON 替代 $.getJSON,其餘不變。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment