Skip to content

Instantly share code, notes, and snippets.

@Natumsol
Last active April 14, 2017 01:03
Show Gist options
  • Save Natumsol/8804fdde645ad412625513fec6809783 to your computer and use it in GitHub Desktop.
Save Natumsol/8804fdde645ad412625513fec6809783 to your computer and use it in GitHub Desktop.
轮询 Demo
var URL= "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20woeid%20in%20(select%20woeid%20from%20geo.places(1)%20where%20text%3D%22nome%2C%20ak%22)&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
/* 响应处理函数 */
function dealWithData(data) {
// 处理响应数据
console.log(data, Date.now());
setTimeout(send, 1000); // 一秒后,再次轮询一次
}
/* 发送请求 */
function send() {
$.get(URL, dealWithData);
}
send();// 启动轮询
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment