Skip to content

Instantly share code, notes, and snippets.

@RadianSmile
Last active May 14, 2017 11:29
Show Gist options
  • Save RadianSmile/3187ef371e30a0505b1fa9ed8fb83107 to your computer and use it in GitHub Desktop.
Save RadianSmile/3187ef371e30a0505b1fa9ed8fb83107 to your computer and use it in GitHub Desktop.
function getJsonUntilSuccess (url , callback ){
$.getJSON (end_point_url , function (data){
if (data.query.results){ // if data.query.results exist , do the following action.
callback (data)
}else {
console.info("reloading : ",url)
getJsonUntilSuccess(url,callback)
}
})
}
@RadianSmile
Copy link
Author

會沒有 result 是因為 Yahoo api 內部的設計不良,有興趣可以參考這篇,加個參數去看他的問題是什麼。

然後我試了一下,多 request 幾次最後還是會有資料,同學可以稍微想一下要怎麼做到。

  • 要怎麼樣讓他 request 不成功時,再重新做一次 request ?

上面程式碼提供範例參考,如果看不懂歡迎在底下留言討論。

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