Last active
April 14, 2017 01:03
-
-
Save Natumsol/8804fdde645ad412625513fec6809783 to your computer and use it in GitHub Desktop.
轮询 Demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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